-
-
Notifications
You must be signed in to change notification settings - Fork 579
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
type-fest@3 - How to declare optional properties in JsonObject? #471
Comments
Unfortunately I can't find (yet) a way to deny the A first workaround is to use a type rather than an interface. Playground
A second workaround is to set If none of the above solutions are suitable, a generic type such as |
Can you mention in which usecases undefined values are a problem for JsonObjects? I use this type to describe configuration files, where some values might be missing but are generally valid. The core tooling like JSON.stringify also has no problem with undefined values - it just omits them. So I'm wondering why this change was made in the first place. The JsonObject type was useful for me, since it described config files well (and didn't allow e.g. Dates or Functions). Now, I can also skip using the type since it's not helpful for me anymore. |
Quote from @voxpelli at #272 (comment)
The last fix tried to work around the problem by supporting both solutions at the same time. Obviously this was not the right thing to do and I think the best one is the one proposed by @voxpelli in the quote above. |
Thanks for the detail, yes I think these two different types would be great to have! |
@peterjuras There is a proposal for a
|
Thanks, I'll follow the PR! 🙏 |
@skarab42 I haven't been following a long a lot on this since my comment there, sorry, can you ping me/request a review if you want me to weigh in with some feedback in this area? :) If you stumble across it that is, I'm sure you're also swamped for time |
Hi, I'm trying to use the new interface CoatLockfileFileEntryBase extends Jsonifiable {
/**
* The relative path from the coat project root directory
*/
path: NonEmptyString;
} leads to the following error: "An interface can only extend an object type or intersection of object types with statically known members.". What I would like to achieve is describe an interface/type which does not allow non-jsonifiable types such as functions etc. How can I do that? |
After the update to version 3.0.0, it is no longer possible to have optional properties on a JsonObject:
Gives a TypeError:
How should this type be used correctly? The code above worked fine with version 2.x.
TypeScript Playground
Upvote & Fund
The text was updated successfully, but these errors were encountered: