Comments (3)
Hi. Since that issue I decided to drop the use of enum in favor of:
enum: Type.Union([Type.Literal('A'), Type.Literal('B')])
Both, serialization and TS types checks works as expected. The generated JSONSchema, on the other hand, differs from enum, but the check is almost the same.
from typebox.
Apologies for the delay. Are you able to get in touch with the fast-json-stringify
guys and get their thoughts on making the enum
type property optional to support varying types?
TypeBox currently allows for varying enum types 'string' and 'number' as TypeScript enum syntax allows for it. As such it omits the type
property based on the example provided at this link...
https://cswr.github.io/JsonSchema/spec/generic_keywords/#enumerated-values
The enum keyword also allows us have different types in the list of allowed values. Consider the schema:
{
"enum": ["Two", 2, true, null]
}
// allowed in TypeScript
enum Example {
A = 'Two',
B = 2,
}
Feel free to link back to this issue. There are technicalities around appropriately inferring the correct type, and how to properly deal with varying enum values in TypeBox. But am interested to see what the 'fast-json-stringify' guys come back with on this.
from typebox.
Hi @fox1t, Thanks for getting back. Glad you found a good work around. :)
Not too sure what can be done for the enum case if TypeBox is to allow both string
and number
enum types. Given that the type
appears to be optional for enum
, I'm tempted to close off this issue.
Will leave open for a week or so in-case someone wants to weight in with thoughts or rationales.
Thanks Again
S
from typebox.
Related Issues (20)
- Unable to create value of custom class type HOT 2
- Migrate to regexp vs string type in pattern HOT 4
- feedback on Refinement API HOT 2
- Type.Date() cause errors with fastify and querybuilder returning type Date HOT 2
- Should coerce type to array HOT 2
- Interconnected interfaces, missing type annotations and maximum length exceeded. HOT 2
- Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. HOT 16
- Add trim option to Type.String() HOT 1
- Should add option to remove redundant prop in Convert() HOT 1
- Metadata missing in custom types HOT 2
- Schema of JSON Schema HOT 3
- Utility type inference appears missing or broken HOT 2
- How to express function optional parameter? HOT 5
- Clean call on extended prisma result object does not work HOT 2
- esm.sh builds are broken if using FormatRegistry HOT 1
- Circular references HOT 4
- Value.Clean causes dereference error on Recursive type with nullable optional union HOT 2
- How to work with dates and timestamps HOT 2
- Issue regarding enums becoming never when using a partial deep method HOT 2
- Support for composite custom kinds HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typebox.