You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 to never , 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:
typeTest<C>=Cextendssome? C :/** Should extend something*/never;
Use Cases
Too improve the diagnostics of conditional types.
Examples
typeNonData<D>=Dextends{data:any}?/**parameter should not contain property data */never:D;declarefunctionnonData<T>(param:NonData<T>):void;constwithData={data:10,a:'a'};nonData(withData);// error, but error message is "parameter should not contain property data "constwithNonData={a:'a'};nonData(withNonData);// pass
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
The text was updated successfully, but these errors were encountered:
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
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: