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
{{ message }}
Repository navigation
Improve diagnostic when string from property is not assignable to string literal. #26413
Error message recommending to add a type annotation to options. This should be detectable because the source of the failing property is a PropertyAssignment in an object literal being assigned to a variable. (If there is no variable assignment, we could still recommend using ``"yes" as "yes"although that isn't as pretty.) Could also come with a codefix. Note that in JS the fix is slightly different: put/** Type (@type) {IceCreamOptions} /` before the `const` or use `/* Type (@type) {"yes"} */ ("yes")`.
Actual behavior:
Error messages says Type 'string' is not assignable to type '"yes" | "no"'. with no information on how to fix it.
I'm going to improve this one, but I found the type of diagnostic is DiagnosticMessage or DiagnosticMessageChain that without position info, and I cannot get the un-assignable props in the object literal simply,
As the problem,i'd like to replace DiagnosticMessageChain with DiagnosticRelatedInformation chain
for isRelatedTo and that will hold the position info
Activity
Kingwl commentedon Aug 28, 2018
add
"yes" as "yes"is soooooooooooooooooooooooo uglyare there any other way to declare the string literal type?
RyanCavanaugh commentedon Aug 28, 2018
Wenlu Wang (@Kingwl) discussion at #10195
Kingwl commentedon Mar 22, 2019
I'm going to improve this one, but I found the type of diagnostic is
DiagnosticMessageorDiagnosticMessageChainthat without position info, and I cannot get the un-assignable props in the object literal simply,As the problem,i'd like to replace
DiagnosticMessageChainwithDiagnosticRelatedInformationchainfor
isRelatedToand that will hold the position infoping Ryan Cavanaugh (@RyanCavanaugh)
Am I missing anything?