question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lib.d.ts types are too loose: provide a "strict" version with more accurate typings?

See original GitHub issue

Let’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:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
falsandtrucommented, Nov 21, 2017

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"

1reaction
mhegazycommented, Nov 21, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found