From ddc77baf4af685b15705a5e2a43f7cc65ae8c5fd Mon Sep 17 00:00:00 2001 From: sinclair Date: Sun, 26 Nov 2023 17:57:34 +0900 Subject: [PATCH] Reimplement Indexed Accessors --- examples/index.ts | 12 +++++++----- package-lock.json | 14 +++++++------- package.json | 5 ++++- src/type/resolve/composite/composite.ts | 2 +- src/type/resolve/modifiers/modifiers.ts | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/index.ts b/examples/index.ts index 106d17d1b..ee5b1c026 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -10,14 +10,16 @@ import { KeyOfStringResolver, IndexedTypeResolver, OmitResolver } from '@sinclai // {} as any, // ]), // ) -console.log( - TypeGuard.TSchema( + +const S = Type.Object({ + x: Type.ReadonlyOptional( Type.Object({ - y: {} as any, + x: Type.Number(), }), ), - '?', -) +}) + +const I = Type.Index(S, ['x']) // // @ts-ignore // Assert.IsEqual(T.properties.x, undefined) diff --git a/package-lock.json b/package-lock.json index 7f6bb758f..88740ec7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "ajv-formats": "^2.1.1", "mocha": "^9.2.2", "prettier": "^2.7.1", - "typescript": "^5.4.0-dev.20231122" + "typescript": "^5.3.2" } }, "node_modules/@esbuild/linux-loong64": { @@ -1317,9 +1317,9 @@ } }, "node_modules/typescript": { - "version": "5.4.0-dev.20231122", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.0-dev.20231122.tgz", - "integrity": "sha512-jEdb2OJDseS3Vi8dg4ARi3ZDqwopyxJP9qsIFawXzTrVSfcIj4WGbBvDx4MIJuwFqGhkJ4G2cJESi3+eN0Rydw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -2279,9 +2279,9 @@ } }, "typescript": { - "version": "5.4.0-dev.20231122", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.0-dev.20231122.tgz", - "integrity": "sha512-jEdb2OJDseS3Vi8dg4ARi3ZDqwopyxJP9qsIFawXzTrVSfcIj4WGbBvDx4MIJuwFqGhkJ4G2cJESi3+eN0Rydw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true }, "uri-js": { diff --git a/package.json b/package.json index 3b41797ce..ee0c13157 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,9 @@ "exports": { "./compiler": "./compiler/index.js", "./errors": "./errors/index.js", + "./type/clone": "./type/clone/index.js", + "./type/guard": "./type/guard/index.js", + "./type/registry": "./type/registry/index.js", "./type/resolve": "./type/resolve/index.js", "./type": "./type/index.js", "./system": "./system/index.js", @@ -61,6 +64,6 @@ "ajv-formats": "^2.1.1", "mocha": "^9.2.2", "prettier": "^2.7.1", - "typescript": "^5.4.0-dev.20231122" + "typescript": "^5.3.2" } } diff --git a/src/type/resolve/composite/composite.ts b/src/type/resolve/composite/composite.ts index 182a3ad5b..df4d88004 100644 --- a/src/type/resolve/composite/composite.ts +++ b/src/type/resolve/composite/composite.ts @@ -58,7 +58,7 @@ export namespace CompositeResolver { export function Resolve(T: T): Resolve { const intersect: any = Type.Intersect(T, {}) - const keys = KeyOfStringResolver.Resolve(intersect) + const keys = KeyOfStringResolver.Resolve(intersect) as string[] const properties = keys.reduce((acc, key) => ({ ...acc, [key]: Type.Index(intersect, [key]) }), {} as TProperties) return Type.Object(properties) as Resolve } diff --git a/src/type/resolve/modifiers/modifiers.ts b/src/type/resolve/modifiers/modifiers.ts index 3b1a1352b..592a4f151 100644 --- a/src/type/resolve/modifiers/modifiers.ts +++ b/src/type/resolve/modifiers/modifiers.ts @@ -142,7 +142,7 @@ export namespace Modifiers { IsOptionalIntersect(T) ? Type.Optional(Type.Intersect(D)) : Type.Intersect(T) - ) as ResolveOptionalIntersect + ) as unknown as ResolveOptionalIntersect } // ---------------------------------------------------------------- // ResolveOptionalUnion