-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Conditional Types, implement custom error message for non matching case #33098
Comments
abdulkareemnalband
changed the title
Conditional Types, implemnt custom error message for non matching case
Conditional Types, implement custom error message for non matching case
Aug 27, 2019
Duplicate of #23689. For now I tend to use something like: type NonData<D> = D extends {data:any} ? [D, 'should not extend { data: any }', never] : D; which is not fool-proof, but works well enough. And FWIW, searching "custom error message" will provide #30289 in the first page of results---which is almost exactly what you are asking for. |
@jack-williams thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Search Terms
#conditionalType , #customErrorMessage
Suggestion
In conditional types
never
is used to remove invalid types from assignments, Error message is is reported as So and so type cannot be assigned tonever
, Which does not inform user what are the actual requirements for usecase.Author of conditional type need to provide some custom error message for particular failure.
this could be provided as doc comment before
never
Ex:
Use Cases
Too improve the diagnostics of conditional types.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: