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
TypeScript Version: 3.8.3 and Nightly
Search Terms:
Code
const fn1 = (cb: (n: number) => void) => { cb(0); }; const fn2 = () => { let a: number | string = ""; fn1(n => a = n); return a; }; type T = ReturnType<typeof fn2>; // T is string
Expected behavior: I define a as number | string explicitly. So I expect T is number | string.
a
number | string
T
Actual behavior: T is string.
string
Playground Link: https://www.typescriptlang.org/play/?ts=nightly#code/MYewdgzgLgBAZmAjDAvDAFMARgLg2PMAVwFssBTAJwEpUA+GANxAEsATWlBgbwCgYBMbOgAM1ANy8AvpN6hIsBACZUGTj36CANuVgBDQqQqUYAHxjRKLMAHNVAInuTB8JOjD0Ye1WAmaBlLpElB56kjK8vFAAngAO5DAAKqoASkEhiXHkADwx8SBwrkp04gIA9GVJMCwQFlBWtkA
Related Issues: #9998
The text was updated successfully, but these errors were encountered:
Two things going on here.
a is initially typed to string: Duplicate of #8513 My search terms were union narrowing assignment Also see discussion in #31734
fn1(...) does not reset the narrowing on a, or renarrow a to number: Duplicate of #9998
fn1(...)
number
Sorry, something went wrong.
Thank you. I understand the situation and the background. Fortunately my case is enough to do like:
const fn2 = (): number | string => { // ... }; type T = ReturnType<typeof fn2>; // T is number | string
No branches or pull requests
TypeScript Version:
3.8.3 and Nightly
Search Terms:
Code
Expected behavior:
I define
a
asnumber | string
explicitly. So I expectT
isnumber | string
.Actual behavior:
T
isstring
.Playground Link:
https://www.typescriptlang.org/play/?ts=nightly#code/MYewdgzgLgBAZmAjDAvDAFMARgLg2PMAVwFssBTAJwEpUA+GANxAEsATWlBgbwCgYBMbOgAM1ANy8AvpN6hIsBACZUGTj36CANuVgBDQqQqUYAHxjRKLMAHNVAInuTB8JOjD0Ye1WAmaBlLpElB56kjK8vFAAngAO5DAAKqoASkEhiXHkADwx8SBwrkp04gIA9GVJMCwQFlBWtkA
Related Issues:
#9998
The text was updated successfully, but these errors were encountered: