Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: support freeform objects w/ index signature instead of unknown keyword #489

Closed
medfreeman opened this issue Apr 23, 2021 · 2 comments · Fixed by #488
Closed

Comments

@medfreeman
Copy link
Contributor

Hi !

This change improves the output of objects without properties by generating an object type with an index signature: { [key: string]: any }.

Now that i think of it, perhaps it'd be better to have { [key: string]: unknown } instead?

Thanks

PR: #488

@horiuchi
Copy link
Owner

Thank you for your contribution! 👍

The type to change seems to be { [key: string]: any }.
Record<string, any> is also good, but it's the same either way.

The {[key: string]: unkown} type seems to be treated differently from Record<string, any>, as shown below.
https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#-k-string-unknown--is-no-longer-a-wildcard-assignment-target

In fact, in the following code, only the case of Record<string, unknown> in line 15 causes a compilation error. For this replacement type, Record<string, any> seems to be a better choice.
https://typescript-play.js.org/?target=7#code/C4TwDgpgBAglC8UBKEDGB7ATgEwDwGdhMBLAOwHMAaKAQ1JAD4BuAKFEigFUFk0s9CJCtQCupANal0Ad1LMWLMsAiYAZjVTQAklADeLKFFXp0ALiikRAWwBGK1gF8WGUoSjFzOxLqMnzARigHVmd0V2Baf3M4b18zKEDg0PDaACZonmJWFzcaAGYMxH9ssNyAFkKLEQAbapKUmgBWSrFsCFUyCGx6txEorh4fY3jEnoiRdIHELOTegqmEsagRCoXLWqWRZoXW9s7u2Yj0frFJGVJBuICgpfRJ06lZTNv5h-OeYsOodFW3p8R1nUvuhtn8Lohdh1SF1WEA

@medfreeman
Copy link
Contributor Author

Makes sense, wasn't sure about this behavior even if i encountered it lots of time already.
So i think the PR is correct as is then.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants