microsoft / TypeScript-DOM-lib-generator

Tool for generating dom related TypeScript and JavaScript library files
Apache License 2.0
616 stars 417 forks source link

Use unknown instead of any in automatically generated definitions #1505

Open guillaumebrunerie opened 1 year ago

guillaumebrunerie commented 1 year ago

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.

saschanaz commented 1 year ago

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.

guillaumebrunerie commented 1 year ago

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

saschanaz commented 1 year ago

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.