lib.d.ts types are too loose: provide a "strict" version with more accurate typings?
See original GitHub issueLet’s use setTimeout
’s typings as an example:
declare function setTimeout(handler: (...args: any[]) => void, timeout: number): number;
declare function setTimeout(handler: any, timeout?: any, ...args: any[]): number;
That’s pretty forgiving. In reality, the recommended usage would be:
declare function setTimeout(handler: (...args: any[]) => void, timeout: number, ...args: any[]): number;
…and if & when variadic kinds are supported (https://github.com/Microsoft/TypeScript/issues/5453), that would become stricter.
Such a loose backwards-compatible lib.d.ts
allows improper usage of native APIs. It would be useful to have a “strict” version that provides only the recommended usage.
In conjunction with #327, it’d be great if a separate type could be created for these types, so we can dependency-inject them in code.
type SetTimeout = (handler: (...args: any[]) => void, timeout: number, ...args: any[]) => number;
declare const setTimeout: SetTimeout;
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Could not find a declaration file for module 'module-name ...
Here are two other solutions. When a module is not yours - try to install types from @types : npm install -D @types/module-name....
Read more >TSConfig Reference - Docs on every TSConfig option
Setting the value to undefined will allow most JavaScript runtime checks ... With .d.ts files, tools like TypeScript can provide intellisense and accurate...
Read more >So What's New in Typescript 3.2?. A quick ... - Bits and Pieces
Typescript is an open-source, strongly-typed, object oriented compiled language. TS 3.2 features strictBindCallApply, Generic spread ...
Read more >TypeScript: Adding Custom Type Definitions for Existing ...
Whether or not a library has type definitions is a big factor in ... project onto an older version of React types definitions...
Read more >TypeScript errors and how to fix them
If you want to export a constant from a definition file ( d.ts ), then you ... If you need a more precise...
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
FYI, all of the bugs of built-in types should basically be filed to https://github.com/Microsoft/TypeScript. The bugs are managed there. See https://github.com/Microsoft/TypeScript/issues?utf8=✓&q=label%3A"Domain%3A lib.d.ts"
yes, and we do list them under breaking changes… see https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#changes-to-dom-apis-in-the-standard-library-1 for an example.