We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi,
We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8.
One case that we are finding slipping through the safety net is the following:
type Foo = 'a' | 'b'; const foo: Foo = 'a'; if (foo === 'bar') { }
Here the Foo type is being compared to an incompatible value 'bar'.
Foo
It would be nice to get an error here similar to an enum comparison error:
enum Foo { a, b } enum Bar { a, b } let foo: Foo; if (foo === Bar.a) { // Operator '===' cannot be applied to types 'Foo' and 'Bar' }
This is especially useful for obtaining a compile time error when the original strings ('a' | 'b') are refactored during the course of development.
('a' | 'b')
I'm aware that there are workarounds involving pseudo string enums, but this is a suggestion for this primitive case.
Thanks.
The text was updated successfully, but these errors were encountered:
This looks like a duplicate of #6149. The general issue is discussed at #6167. A fix exists at #6196.
Sorry, something went wrong.
This has been fixed
No branches or pull requests
Hi,
We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8.
One case that we are finding slipping through the safety net is the following:
Here the
Foo
type is being compared to an incompatible value 'bar'.It would be nice to get an error here similar to an enum comparison error:
This is especially useful for obtaining a compile time error when the original strings
('a' | 'b')
are refactored during the course of development.I'm aware that there are workarounds involving pseudo string enums, but this is a suggestion for this primitive case.
Thanks.
The text was updated successfully, but these errors were encountered: