Expect to use @throws in lib/*.d.ts to mark which methods may throw err
See original GitHub issueSuggestion
Use @throws
to mark the corresponding error on the method in the .d.ts file in the lib directory
🔍 Search Terms
@throws
jsdoc
comments
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
⭐ Suggestion
Use @throws
to mark the corresponding error on the method in the .d.ts file in the lib directory
📃 Motivating Example
/**
* Converts a JavaScript Object Notation (JSON) string into an object.
* @param text A valid JSON string.
* @param reviver A function that transforms the results. This function is called for each member of the object.
+* @throws {SyntaxError} if the string to parse is not valid JSON.
* If a member contains nested objects, the nested objects are transformed before the parent object is.
*/
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
💻 Use Cases
want to be able to write code when you know that you need to beware of these unpredictable behavior
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:5
Top Results From Across the Web
How do I prevent VS 2022 to display typescript errors with d.ts ...
Click "OK" and a popup menu will appear that asks you if you want to "Apply changes to this folder, subfolders, and files"....
Read more >TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >Documentation - TypeScript 4.4
When we pass an object literal to something with an expected type, TypeScript will look for excess properties that weren't declared in the...
Read more >Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... so if you are using TypeScript, you may want to consider moving "ts"...
Read more >Configuring TypeScript compiler - inDepthDev
TypeScript files are compiled into JavaScript using TypeScript compiler. ... Note: By specifying lib you simply tell TS compiler to not throw error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I like this idea, but it seems much more useful if this information could be propagated by typescript, so that a function which calls something annotated with
@throws
and doesn’t catch is also considered as throwing.Something like typescript-eslint/no-floating-promises would be interesting. In this rule unhandled promises shows an error on vscode.