-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Proposal: throw type #30289
Comments
Duplicate #23689 ? |
Yes. Does that under considering? |
I don't think this is a duplicate of #23689. That proposal is for a new type that represents an exception during type-checking and should not be related to any other type: the dual of I believe this proposal is for something that is essentially a labelled One potential issue with this proposal is that if the type Colour = "blue" | "green" | string to give autocompletion suggestions, but TypeScript removes the literals because they are semantically meaningless. |
I think the broad use case of "Use the type system to indicate error states" is what's being discussed in both issues, with the particulars of topness/bottomness of those flagging types being a design detail to hammer out later - certainly we wouldn't do both, so figuring which is preferable is something we can track at #23689 |
Search Terms
throw
type
proposal
expression
language service
Summary
Provide custom error message on type level. By
throw 'error message'
(which evals tonever
)Detail
Now we have type
never
to represent a type that has 0 value in it. But it does not provide enough information for it.For example:
This prevents we accidentally provide the wrong parameters. But it's not clear enough.
Let's imagine we get a new type of Type expression like this:
throw 'Any string'
that equals never but show error details in the language service.This is useful in complex types.
Grammar
Evaluate:
Any throw expression in type context evaluates to
never
.Additional information to language service
throw 'string'
evaluates to 'string'Hacks
Problem of this way to strict caller's generic
I cannot specify one thing to be
T extends Q ? A : never
, in the same time assign it as A.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: