Skip to content

'i32 | null' should not be assignable to 'i32' #233

Closed
@andy-hanson

Description

@andy-hanson
export function f(n: i32 | null): i32 {
	return n; // Should be an error
}

// This function should never return true true since 'f' returns 'i32' which is not nullable.
// But it does return true!
export function test(): boolean {
	return f(null) === null;
}

Since f is a compile error for string | null or ClassName | null, I think it should be an error for i32 | null too.
Instead, it compiles with no error, and it can apparently return a value its return type didn't declare, tested by calling test() from JS which returns true.

EDIT: This isn't a compile error for string | null either, but I think it should be.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions