We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
throw
Error Type, throws, throw, throw keyword
add a throw keyword that when it reached in a type it reports a message/error. it's useful when used with "Template literal types".
usage:
type RouteParams<T extends string> = T extends `/${infer Route}/:${infer Param}` ? { [Route]: { [Param]: string }} : throws `${T} doesn't have a "/:param" part`; function addRoute<T extends string>(path: T, params: RouteParams<T>) ...
for now, we can only return types like this to inform the user why the input is incorrect:
type Error<T> = T & { error: true }; type RouteParams<T extends string> = T extends `/${infer Route}/:${infer Param}` ? { [Route]: { [Param]: string }} : Error<`${T} doesn't have a "/:param" part`>; function addRoute<T extends string>(path: T, params: RouteParams<T>) ...
which doesn't show error lines and place of the error message is really indirect and the user may not found it/
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered:
Duplicate of #23689.
Sorry, something went wrong.
No branches or pull requests
Search Terms
Error Type, throws, throw, throw keyword
Suggestion
Explanation
add a
throw
keyword that when it reached in a type it reports a message/error.it's useful when used with "Template literal types".
usage:
for now, we can only return types like this to inform the user why the input is incorrect:
which doesn't show error lines and place of the error message is really indirect and the user may not found it/
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: