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
ternary, conditional expression, recursion,
I propose that the following code should error
declare const b: boolean; declare const a: any; const s: string = b ? a : 42;
because number is not assignable to string.
number
string
This is already the case for the equivalent return statement "assignment", as of #56941.
function foo(b: boolean, a: any): string { return b ? a : 42 }
So I think it would make sense to be consistent.
My real world code looked something like this
declare const x: unknown; const s: string = x != null ? (x as any).prop : undefined
Another related example, is that this code should be an error
declare const a: any; const s: string = a ?? 24;
Which relates to #51665 (comment), where an error should/would occur if the RHS of the ?? were checked separately.
??
any
The text was updated successfully, but these errors were encountered:
Duplicate of #31518.
Sorry, something went wrong.
Gotcha π Would just say that the only difference with this issue is that the context has now changed, due to #56941.
No branches or pull requests
π Search Terms
ternary, conditional expression, recursion,
β Viability Checklist
β Suggestion
I propose that the following code should error
because
number
is not assignable tostring
.This is already the case for the equivalent return statement "assignment", as of #56941.
So I think it would make sense to be consistent.
π Motivating Example
My real world code looked something like this
Another related example, is that this code should be an error
Which relates to #51665 (comment), where an error should/would occur if the RHS of the
??
were checked separately.π» Use Cases
any
as much as possibleThe text was updated successfully, but these errors were encountered: