diff --git a/src/constants/TypeTokens.ts b/src/constants/TypeTokens.ts index ede64a75..a79154e1 100644 --- a/src/constants/TypeTokens.ts +++ b/src/constants/TypeTokens.ts @@ -97,7 +97,9 @@ export const SIMPLE_DICT_TOKENS = [ export const SIMPLE_ARRAY_TOKENS = [ "Array", "Array", + "Array" as `Array`, "Array", + "Array" as `Array`, "Array", "Array", `Array`, @@ -279,5 +281,3 @@ export const TYPE_TOKEN_ALL = [ ...TYPE_TOKEN_PARAM_STR, ...TYPE_TOKEN_PARAM_TIME ] as const; - - diff --git a/src/types/runtime-types/SimpleType.ts b/src/types/runtime-types/SimpleType.ts index 051936de..0b05d2d0 100644 --- a/src/types/runtime-types/SimpleType.ts +++ b/src/types/runtime-types/SimpleType.ts @@ -111,8 +111,12 @@ export type SimpleTypeArray = T extends "Array" ? any[] : T extends "Array" ? string[] +: T extends `Array` +? Array> : T extends "Array" ? number[] +: T extends `Array` +? Array> : T extends "Array" ? boolean[] : T extends "Array" @@ -122,12 +126,14 @@ export type SimpleTypeArray = T extends "Array" export type SimpleTypeMap = T extends "Map" ? Map : T extends `Map<${infer Key extends MapKeys}, ${infer Value extends MapValues}>` +// eslint-disable-next-line no-use-before-define ? Map, SimpleType> : never; export type SimpleTypeSet = T extends "Set" ? Set : T extends `Set<${infer Type extends SetTypes}>` +// eslint-disable-next-line no-use-before-define ? Set> : never; @@ -160,6 +166,3 @@ export type SimpleType = T extends SimpleScalarToken : never; export type StructuredStringType = any; - - - diff --git a/tests/runtime/SimpleType.test.ts b/tests/runtime/SimpleType.test.ts index d9a28f5b..a2598796 100644 --- a/tests/runtime/SimpleType.test.ts +++ b/tests/runtime/SimpleType.test.ts @@ -30,6 +30,24 @@ describe("SimpleType", () => { ]; }); + it("String and Numeric literals", () => { + type Answer = SimpleType<"string(42)">; + type Answer2 = SimpleType<"number(42)">; + + type FooBar = SimpleType<"string(foo,bar)">; + type OneTwo = SimpleType<"number(1,2)">; + + type cases = [ + Expect>, // + Expect>, // + Expect>, // + Expect>, // + ]; + const cases: cases = [ + true, true, true, true + ]; + }) + it("optional types", () => { type Str = SimpleType<"Opt">; type Num = SimpleType<"Opt">;