-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
index never on tuple returns union #53345
Comments
This happens for all index signatures, for example: type Rec = Record<string, boolean>[never] // boolean
|
Yes, const x: number = 1 as never The question is what does type X = ['a', 'b'][any] // 'a' | 'b'
type Y = ['a', 'b'][number] // 'a' | 'b'
type Z = ['a', 'b'][never] // 'a' | 'b'
But
So to me yielding |
btw, while union order doesn't matter, Playground yields |
Union order is a pure implementation detail: It depends on the order the constituent types are first instantiated by the compiler and thus can change depending on the surrounding code, the order in which files are compiled (in a multi-file project) or even with different compiler settings. For all intents and purposes, you should treat it as random. |
I don't follow the logic in the OP at all.
I think you could argue either way whether the "correct" bound on that type is |
Yes, And yes, the question should focus on what it resolves/bounds to. The problem and confusion is that the current behavior does not map logically. Consider type as set: When mapped using "functor" [1, 2][never] // 1 | 2
[1, 2][0] // 1
[1, 2][0 | 1] // 1 | 2
[1, 2][any] // 1 | 2 That means: is transformed to meaning That's why It should resolve to |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Reopen? |
I'd consider it, but again, a motivating scenario is needed given that the current result is still a correct upper bound. |
Do you think my reasoning here is correct? #53345 (comment) That tries to reason that returning |
I think your logic and my logic are both correct, and both create correct upper bounds. Generally we've found it's disruptive to just go change stuff without being able to point to a code example and say "We made this work now" as justification for making those changes. Inevitably, changes cause breaks, and people want to know why you broke them, and there should be a better answer than "Someone used ∈ correctly" |
No problem. I understand that changes could break someone else's code. I understand that TypeScript need to make trade-offs, balance between usability vs soundness. It might even be too late to change now, but things like these make the type system harder to reason, thus make it harder to understand and write correct (type-level) code. I'm going to have this logic in the type R = At<[1, 2, 3], never> // never This way, there is at least some way to obtain that behavior. |
Bug Report
Is this a bug?
🔎 Search Terms
index, never, tuple
🕗 Version & Regression Information
TypeScript: 3.2 - 5.0.2
never
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
UPDATE:
is strike out, as the expression
[1, 2][never]
is value as:The text was updated successfully, but these errors were encountered: