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
TypeGuard.IsEnum #811
Comments
@aleclarson Hi! Ah, this is interesting :) TypeBox doesn't actually have an internal concept of import { Type, TypeGuard } from '@sinclair/typebox'
enum Foo { A, B }
const T = Type.Enum(Foo) // {
// anyOf: [
// { const: 0, type: 'number', [Symbol(TypeBox.Kind)]: 'Literal' },
// { const: 1, type: 'number', [Symbol(TypeBox.Kind)]: 'Literal' }
// ],
// [Symbol(TypeBox.Hint)]: 'Enum',
// [Symbol(TypeBox.Kind)]: 'Union'
// }
const R = TypeGuard.IsUnionLiteral(T) // true - stand in for Enum representation There are considerations to changing this in future (as import { Type, TypeGuard } from '@sinclair/typebox'
enum Foo { A, B }
const T = Type.Enum(Foo) // { enum: [0, 1]: [Symbol(TypeBox.Kind)]: 'Enum' }
const R = TypeGuard.IsEnum(T) // true - as we have a actual enum representation For now though, the TypeGuard.IsUnionLiteral() is the best approximation for Enum. Hope this brings some insights! |
@aleclarson Heya, Might close off this one as IsEnum is currently out of scope until TB supports a Cheers! |
This should exist :)
The text was updated successfully, but these errors were encountered: