diff --git a/ark/type/__tests__/cast.test.ts b/ark/type/__tests__/cast.test.ts index b26f4d3f20..619a3e3933 100644 --- a/ark/type/__tests__/cast.test.ts +++ b/ark/type/__tests__/cast.test.ts @@ -5,40 +5,40 @@ import { type, type Type } from "arktype" contextualize(() => { describe("type.cast", () => { it("primitive", () => { - const foo = type("string" as type.as<"foo">).t + const foo = type("string" as type.cast<"foo">).t attest<"foo">(foo) }) it("object", () => { // definitions that are cast can't be validated - attest<{ a: "foo" }>(type({ a: "string" } as type.as<{ a: "foo" }>).t) + attest<{ a: "foo" }>(type({ a: "string" } as type.cast<{ a: "foo" }>).t) }) it("primitive to object", () => { - attest<{ a: "foo" }>(type("string" as type.as<{ a: "foo" }>).t) + attest<{ a: "foo" }>(type("string" as type.cast<{ a: "foo" }>).t) }) it("object to primitive", () => { - attest<"foo">(type({ a: "string" } as type.as<"foo">).t) + attest<"foo">(type({ a: "string" } as type.cast<"foo">).t) }) it("infer function", () => { type F = () => boolean - const constructable = type({} as type.as) + const constructable = type({} as type.cast) attest(constructable.t) attest(constructable.infer) attest(constructable.in.infer) }) it("infer constructable", () => { - const constructable = type({} as type.as) + const constructable = type({} as type.cast) attest(constructable.t) attest(constructable.infer) attest(constructable.in.infer) }) it("undefined", () => { - const foo = type("string" as type.as<"foo">).t + const foo = type("string" as type.cast<"foo">).t attest<"foo">(foo) }) }) diff --git a/ark/type/__tests__/defaults.test.ts b/ark/type/__tests__/defaults.test.ts index 756e541d2b..e5bfa17d5a 100644 --- a/ark/type/__tests__/defaults.test.ts +++ b/ark/type/__tests__/defaults.test.ts @@ -569,8 +569,8 @@ contextualize(() => { it("allows string sybtyping", () => { type({ - foo: [/^foo/ as type.as<`foo${string}`>, "=", "foobar"], - bar: [/bar$/ as type.as<`${string}bar`>, "=", () => "foobar" as const] + foo: [/^foo/ as type.cast<`foo${string}`>, "=", "foobar"], + bar: [/bar$/ as type.cast<`${string}bar`>, "=", () => "foobar" as const] }) }) diff --git a/ark/type/__tests__/realWorld.test.ts b/ark/type/__tests__/realWorld.test.ts index 48588b68b4..937bf23cc4 100644 --- a/ark/type/__tests__/realWorld.test.ts +++ b/ark/type/__tests__/realWorld.test.ts @@ -39,7 +39,7 @@ contextualize(() => { const MockTimeStub = class TimeStub {} const types = scope({ - timeStub: ["instanceof", MockTimeStub] as type.as, + timeStub: ["instanceof", MockTimeStub] as type.cast, account: "clientDocument&accountData", clientDocument: { "id?": "string", diff --git a/ark/type/__tests__/scope.test.ts b/ark/type/__tests__/scope.test.ts index 4caff9858e..403c8c8b8a 100644 --- a/ark/type/__tests__/scope.test.ts +++ b/ark/type/__tests__/scope.test.ts @@ -440,7 +440,7 @@ b.c.c must be an object (was missing)`) "[string]": "value" }, value: "primitive | record | value[]", - castValue: "value" as type.as + castValue: "value" as type.cast }).export() // TS type display blows up but it's equivalent to Value diff --git a/ark/type/attributes.ts b/ark/type/attributes.ts index 37ae47bf8f..f9c8079444 100644 --- a/ark/type/attributes.ts +++ b/ark/type/attributes.ts @@ -559,7 +559,7 @@ export type inferPredicate = export type inferPipes = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes< - pipes[0] extends type.as ? inferPipe + pipes[0] extends type.cast ? inferPipe : inferMorphOut extends infer out ? (In: distill.withAttributes.In) => Out : never, diff --git a/ark/type/keywords/keywords.ts b/ark/type/keywords/keywords.ts index a4ea3d7a1f..48f7600896 100644 --- a/ark/type/keywords/keywords.ts +++ b/ark/type/keywords/keywords.ts @@ -79,15 +79,10 @@ export const keywords: Module = ark.export() export const type: TypeParser<{}> = ark.type as never export declare namespace type { - export interface as { - [inferred]?: castTo + export interface cast { + [inferred]?: to } - /** - * @deprecated Use type.as instead - */ - export type cast = as - export type errors = ArkErrors /** @ts-ignore cast variance */ diff --git a/ark/type/methods/object.ts b/ark/type/methods/object.ts index f448705e64..a447f5ae93 100644 --- a/ark/type/methods/object.ts +++ b/ark/type/methods/object.ts @@ -43,14 +43,14 @@ interface Type extends BaseType { * @example type({ foo: "string" }).get("foo") // Type */ get, r = arkGet>( - k1: k1 | type.as + k1: k1 | type.cast ): instantiateType get< const k1 extends arkIndexableOf, const k2 extends arkIndexableOf> >( - k1: k1 | type.as, - k2: k2 | type.as + k1: k1 | type.cast, + k2: k2 | type.cast ): instantiateType, k2>, $> extends infer r ? r : never get< const k1 extends arkIndexableOf, @@ -58,9 +58,9 @@ interface Type extends BaseType { const k3 extends arkIndexableOf, k2>>, r = arkGet, k2>, k3> >( - k1: k1 | type.as, - k2: k2 | type.as, - k3: k3 | type.as + k1: k1 | type.cast, + k2: k2 | type.cast, + k3: k3 | type.cast ): instantiateType /** @@ -68,7 +68,7 @@ interface Type extends BaseType { * @example type({ foo: "string", bar: "number" }).pick("foo") // Type<{ foo: string }> */ pick = never>( - ...keys: (key | type.as)[] + ...keys: (key | type.cast)[] ): Type< { [k in keyof t as Extract, key>]: t[k] @@ -81,7 +81,7 @@ interface Type extends BaseType { * @example type({ foo: "string", bar: "number" }).omit("foo") // Type<{ bar: number }> */ omit = never>( - ...keys: (key | type.as)[] + ...keys: (key | type.cast)[] ): Type< { [k in keyof t as Exclude, key>]: t[k] @@ -203,7 +203,7 @@ type BaseMappedTypeProp = merge< BaseMappedPropInner, { key: k - value: type.as + value: type.cast } > @@ -211,7 +211,7 @@ type OptionalMappedTypeProp = merge< OptionalMappedPropInner, { key: k - value: type.as + value: type.cast default?: v } > diff --git a/ark/type/parser/definition.ts b/ark/type/parser/definition.ts index cb3fe84ae2..fb694cc5b9 100644 --- a/ark/type/parser/definition.ts +++ b/ark/type/parser/definition.ts @@ -65,7 +65,7 @@ export const parseObject = (def: object, ctx: BaseParseContext): BaseRoot => { export type inferDefinition = [def] extends [anyOrNever] ? def - : def extends type.as ? + : def extends type.cast ? // {} as a def is handled here since according to TS it extends { " arkInferred"?: t }. // Unlike in TS however, ArkType object literals are constrained to object // so we use that as the base type inferred when parsing {}. @@ -98,7 +98,7 @@ export type validateDeclared = : validateDefinition type validateInference = - def extends RegExp | type.as | ThunkCast | TupleExpression ? + def extends RegExp | type.cast | ThunkCast | TupleExpression ? validateShallowInference : def extends array ? declared extends array ? @@ -135,9 +135,9 @@ type declarationMismatch = { // functions are ignored in validation so that cyclic thunk definitions can be // inferred in scopes -type Terminal = type.as | Fn +type Terminal = type.cast | Fn -export type ThunkCast = () => type.as +export type ThunkCast = () => type.cast type BadDefinitionType = Exclude