Revision 0.31.14 (#584)

* Revert 0.31.8 Enum

* Intercept for Enum on StaticDecode
This commit is contained in:
sinclairzx81
2023-09-06 05:12:54 +09:00
committed by GitHub
parent 4edc46c2ef
commit 6b27faba28
8 changed files with 73 additions and 16 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ import { Type } from '@sinclair/typebox'
// expect empty enum to be string (as empty enums T[keyof T] evaluates as string)
enum E {}
const T = Type.Enum(E)
Expect(T).ToStaticNever()
Expect(T).ToStatic<string>()
}
{
// expect empty enum to be never
+1 -5
View File
@@ -78,9 +78,5 @@ import { Type, Static } from '@sinclair/typebox'
C = 'Z',
}
const T = Type.Record(Type.Enum(E), Type.Number())
Expect(T).ToStatic<{
X: number
Y: number
Z: number
}>()
Expect(T).ToStatic<{}>()
}
+13
View File
@@ -278,3 +278,16 @@ import { Expect } from './assert'
Expect(T).ToStaticDecode<number>()
Expect(GenericIntersect(T)).ToStaticDecode<1>()
}
{
// should decode enum
enum E {
A,
B,
C,
}
const T = Type.Transform(Type.Enum(E))
.Decode((value) => 1 as const)
.Encode((value) => E.A)
Expect(T).ToStaticDecode<1>()
Expect(T).ToStaticEncode<E>()
}