Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic type inference for boolean literals fails #19896

Closed
patsissons opened this issue Nov 10, 2017 · 6 comments
Closed

generic type inference for boolean literals fails #19896

patsissons opened this issue Nov 10, 2017 · 6 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@patsissons
Copy link

TypeScript Version: 2.6.1
Code

function test<T>(x: T, f: (y: T) => void) { return x; }
let z: false = false;
test(z, x => { z = x; });
// ------------^
// [ts]
// Type 'boolean | undefined' is not assignable to type 'false | undefined'.
// Type 'true' is not assignable to type 'false | undefined'.

Expected behavior:

z and x should be of the same type

Actual behavior:

x is being inferred as boolean instead of false

@patsissons
Copy link
Author

patsissons commented Nov 10, 2017

I'll try and test this in @next when i get a chance, just trying to get this issue posted for now.

confirmed on 2.7.0-dev.20171109:

tsc "test.ts"

test.ts(3,16): error TS2322: Type 'boolean' is not assignable to type 'false'.

@Proculopsis
Copy link

// let z: false = false;
let z: boolean = false;

Isn't this a compiler bug, letting you use 'false' as a type rather than 'boolean'?

@patsissons
Copy link
Author

typescript permits boolean literals as type declarators. this is particularly relevant in React development, since false means do not render anything, but true cannot be rendered.

@mhegazy mhegazy added the In Discussion Not yet reached consensus label Nov 20, 2017
@RyanCavanaugh RyanCavanaugh added the Suggestion An idea for TypeScript label Nov 20, 2017
@RyanCavanaugh
Copy link
Member

@mhegazy what is the inferred suggestion here?

@Qwertiy
Copy link

Qwertiy commented Jul 11, 2020

Seems working fine on 3.9.2.

@jakebailey
Copy link
Member

Just looking at old issues; this was fixed back by #27042.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants