Giter VIP home page Giter VIP logo

Comments (3)

fox1t avatar fox1t commented on May 12, 2024 2

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.

sinclairzx81 avatar sinclairzx81 commented on May 12, 2024

@apyrkh

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.

sinclairzx81 avatar sinclairzx81 commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.