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

Add rule to detect invalid type literal assertions #163

Closed
ajafff opened this issue Apr 3, 2018 · 0 comments
Closed

Add rule to detect invalid type literal assertions #163

ajafff opened this issue Apr 3, 2018 · 0 comments
Assignees

Comments

@ajafff
Copy link
Member

ajafff commented Apr 3, 2018

microsoft/TypeScript#14156

These are currently no compile error:

const True = false as true;
const one = 2 as 1;
const str = 'hello' as 'str';

declare const foo: 'foo';
foo as 'string';

declare const bar: 'foo' | 'bar';
bar as 'string';

// this should still be allowed:
bar as 'foo';

This only affects literals asserted to a different literal of the same widened type.

These are handled correctly:

1 as 'str';                    // Type 1 is not comparable to type "str"
['hello'] as ['str'];          // Type "hello" is not comparable to type "str"
({a: 'hello'} as {a: 'str'});  // Type "hello" is not comparable to type "str"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant