-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
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
TypedArray constructor compile error #61134
Comments
Assignment narrows the type. Here's a simplified example: const value: string | number = 123; // Always assigning a number.
value; // Variable is typed number, because the compiler knows we always assign a number. In your Ok case the variable is narrowed to |
Oh, I wasn't aware of that, interesting. I can see this being useful in many cases, I could also argue that if the developer declares a type explicitly then no further automatic narrowing should be done..I'm guessing the reason it still happens is that it can only help catch more errors, so there is no advantage not doing it. |
🔎 Search Terms
When creating a class for a typed array, if this class is returned by indexing into an object, I get a compile error.
See attached playground link.
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBDAnmYcAqzgBMCCUoCGiAwhAHYDOMUArgMYzRwC8AUAJAA+cAqgJZkYADjyES5KrQbQO3foICMANlFFSlavUZRZvATADMAJlXiNU7boCSgkfjUTN0nVzg2Yy0+slaZr98ZejhZ+3ABiADYQBIYm9mY+zqysoJCwcHSOcN4wBIIULHAA3qxwcABCAJpoAKIAXHAArApGAAwANKW8AHIAylYA4t01ACIA+lW1Dc1GCp1lvQASAPIASmjTLUbzPf1Do2NLaxtNLQY7Vt0nMwAsnew8fYPD45fXLY2dHGEAMss47yMSk6AF9kmVUtB4JkNHACPFyogMChCiV2ABtHJ5GAUAB0kxqAF0yiTSWUGu47GJ7pjHNi8Y89i8JtUieS9LZTDSsflcUd1sSyaSKYoVPFuXTeYzngd+WhiQ15B4xdSOLSNPTcW9BULhW5BIFxWqeTjcdL9q8rjrFfpDaqMSa8b9-vLdSSGpForEuawQXCCjCqABuZKsQPwABGNAAZtHgFBCmRgAB3OCmcoxuNQAAUAEoQ6wAPSFuDLADWrBKZXDafixAiBAoFAayOwQXMvgTzH1wlMIerWToiZTtbE9cbFGzUdj8facA6cAU+d9yWL2QgAFswHwIqgavgZFWMoPN5Ak4JW4VHfjWf3j7CvA2my3MLg68FO4V4WJEa30Zkt3IYAL0wQk7xrIduyTVNHwnKdM1nec5yXIM4DXGpwGABhsHnABaBQ4SgABzGgN2AnEV2SIA
💻 Code
🙁 Actual behavior
The last line returns a compile error.
🙂 Expected behavior
There should be no compile errors.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: