Skip to content

Commit

Permalink
Reimplement Indexed Accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 26, 2023
1 parent 1f5b632 commit ddc77ba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
12 changes: 7 additions & 5 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/type/resolve/composite/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export namespace CompositeResolver {

export function Resolve<T extends TObject[]>(T: T): Resolve<T> {
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<T>
}
Expand Down
2 changes: 1 addition & 1 deletion src/type/resolve/modifiers/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export namespace Modifiers {
IsOptionalIntersect(T)
? Type.Optional(Type.Intersect(D))
: Type.Intersect(T)
) as ResolveOptionalIntersect<T>
) as unknown as ResolveOptionalIntersect<T>
}
// ----------------------------------------------------------------
// ResolveOptionalUnion
Expand Down

0 comments on commit ddc77ba

Please sign in to comment.