TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Use unknown instead of any in automatically generated definitions

Open guillaumebrunerie opened this issue 3 years ago • 4 comments

From what I understand, this library uses an automated system to read the specs and extract the types from them. Occasionally the spec does not specify any type and so this library defaults to any (for instance see #1237 for structuredClone).

I'd like to suggest to modify the tool to use unknown instead by default (and never use any), to err on the side of type safety.

guillaumebrunerie avatar Feb 26 '23 09:02 guillaumebrunerie

Using unknown would be indeed more strict, but doing so also will break many many existing codes, so I'm not sure we can do this. This at least requires some kind of conditional compiling.

saschanaz avatar Mar 18 '23 18:03 saschanaz

Is it possible to do it only for future APIs? Or would it automatically apply to existing APIs as well?

guillaumebrunerie avatar Mar 18 '23 20:03 guillaumebrunerie

Is it possible to do it only for futurs APIs?

Technically possible but the generator will need to maintain a big list of 'old APIs'. And that will also break consistency.

saschanaz avatar Mar 18 '23 20:03 saschanaz

Bump, this goes against the very purpose of typing, and is many causing issues in real code, latest occurence https://github.com/lichess-org/lila/pull/16296.

A way to specify it, a breaking change or an alternative lib would be welcome.

kraktus avatar Oct 30 '24 19:10 kraktus