-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Const numbers that index into tuples do not produce the correct type #6678
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
Comments
We did this for const enums (#3411); I don't see why we wouldn't for this case either |
It's not compile because you need a cast, it does not recognize ID as 0, so it does not detect you try to get the first entry of the union types, so it does not cast it. What is important to read is the tuple have first entry as number and second entry as string. Without const, data[0] return a number and data[1] return a string. With const it does not work. |
Should this be changed too? |
i do not see why not. |
got bitten by it, please fix asap: nightly build Oct 24, 2016 const values: [number, string] = [1, 'a'];
const one = values[0]; // number, OK
const index = 0; // index is `0` (not just a number)
const another = values[index]; // expected number, actual: string | number <-- WHY? |
@RyanCavanaugh this seems to be fixed when checking TypeScript 3.3.3. |
Hi,
Constants aren't evaluate to access and cast properly union types values:
Is there a reason why it's not supported ?
Regards,
Sébastien
The text was updated successfully, but these errors were encountered: