Skip to content

"typeof" operator should remove wideningness #16337

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

Closed
RyanCavanaugh opened this issue Jun 7, 2017 · 1 comment
Closed

"typeof" operator should remove wideningness #16337

RyanCavanaugh opened this issue Jun 7, 2017 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@RyanCavanaugh
Copy link
Member

Source https://stackoverflow.com/questions/44421946/does-typescript-2-3-3-loose-type-information-on-array-spread

This code:

const A = "A", B = "B";
type T_A = typeof A;
type T_B = typeof B;
type M = T_A | T_B;
const m: Array<M> = ["A"];
const n = [...m]; // n: string[]

behaves differently from this code, which is quite surprising:

const A = "A", B = "B";
type T_A = "A"; // was: typeof A
type T_B = "B"; // was: typeof B
type M = T_A | T_B;
const m: Array<M> = ["A"];
const n = [...m]; // n: M[], was string[]

Once someone is using typeof, it seems very unlikely they want a widening type and we should revert to a non-widening form of the type.

@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Jun 7, 2017
@RyanCavanaugh
Copy link
Member Author

Nah

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant