Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork548
Made additionalProperties add an index signature to unkown when explicit properties are specified#1719
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
…cit properties are specified
Hey@filkalny-thimble, why do you prefer unknown instead of any? |
filkalny-thimble commentedFeb 4, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
constanyTyped:any={foo:"bar"}typeMyType={foo:{faz:string}}constconcreteTyped:MyType=anyTyped;// TS sees no issues with this// This will fail with "cannot access properly length of undefined"console.log(concreteTyped.foo.faz.length); The same example with constunknownTyped:unknown={foo:"bar"}typeMyType={foo:{faz:string}}// TS would not be happy with the following:// const concreteTyped: MyType = unknownTyped;// so instead you have to narrow the typeconstisMyType=(val:unknown):val isMyType=>typeofval==="object"&&"foo"inval&&typeofval.foo==="object"&&"faz"inval.foo&&typeofval.foo.faz==="string";if(isMyType(unknownTyped)){constconcreteTyped:MyType=unknownTyped;// Now we can operate safelyconsole.log(concreteTyped.foo.faz.length);} |
@filkalny-thimble I see. OpenAPI has a concept ofAny Type schema that matches any data type. Would you also expect Any Type schema to result in |
filkalny-thimble commentedFeb 4, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, this is what I would expect, despite the coincidentally similar naming to typescript's |
@filkalny-thimble Great, I was hoping that would be the answer. I think we have two approaches towards handling these cases, |
The only reasonable case I would see for having a user switch built in is so that a breaking change is not introduced into existing code bases. This option should be communicated as such; maybe |
@filkalny-thimble I see. I might make the switch to unknown as it makes sense. We've got additionalProperties working inour fork, just need to offer the option to make them unknown over any |
@filkalny-thimble hej, I releasedv0.27.30 with a bunch of |
This allows objects with additional properties to be used without polluting the rest of the codebase with
anys.