You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RyanCavanaugh
changed the title
Union of string literals is widened incorrectly when compared to never
Union of string literals is widened in error message when compared to never
Dec 2, 2020
RyanCavanaugh
changed the title
Union of string literals is widened in error message when compared to never
Union of string literals is incorrectly widened in error message when compared to never
Dec 2, 2020
// Use this literal instead of "never" to ensure that a switch statement is exhaustive.// See issue: https://github.com/microsoft/TypeScript/issues/41707typeNeverStringLiteral="__THIS_SHOULD_BE_UNREACHABLE__";exportfunctionassertUnreachable(value: NeverStringLiteral): never{thrownewError(`Unreachable: ${value}`);}// usagetypeActionTypes='a'|'b'|'c'functionreducer(state: {},action: {type: ActionTypes}){switch(action.type){case'a':
returnstatedefault: {// 🚫 Argument of type '"b" | "c"' is not assignable to parameter of type '"__THIS_SHOULD_BE_UNREACHABLE__"'assertUnreachable(action.type);}}}console.log(reducer({},{type: 'b'}))
hyzyla
added a commit
to hyzyla/TypeScript
that referenced
this issue
Aug 27, 2024
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 4.1.2, 4.0.5 (worked better in 3.9.7)
Search Terms: "string is not assignable to type never" (all 15 issues I found look slightly different I think)
Code
Expected behavior: like in 3.9.7, the error message should be
Argument of type '"b"' is not assignable to parameter of type 'never'
Actual behavior:
Argument of type 'string' is not assignable to parameter of type 'never'
- which is too wide to be actually helpful :(Playground Link: https://www.typescriptlang.org/play?ts=4.1.2#code/GYVwdgxgLglg9mABAQwM6oKYCcoFUxYbIQAWyARgDYYAUA+gFyJgYBu2AlE63DACaIA3gF8AUKID0ExCFTIA5hlFQAngAcMiAILR4YACrqMqRAF5EAcmQXEAH0vkL40JFgJEhPiAjYaqKMhQGEwiADQougghqhpMOm4GRqjCHEKiiIioAO4wUKQ0xAkAdDEYqYLpGYgQaJpWFgyVVR4YUCBYSP6BSs18GMDIIJRQIU1VaJg4+ITEZFS0hXolRhxjGYRtHZkBQWNiGWJiohAIqHDURZRw8jSe3r5hQqVMFo4pHEA (change the version number to see the previous error)
Related Issues: ?
The text was updated successfully, but these errors were encountered: