A
arktype•2mo ago
Sorato

implicit any if i import from another scope

if i have 2 files (testA.ts and testB.ts) which have the following contents: testA.ts:
import {type} from "arktype";
import {modB} from "./testB";

export const modA = type
.scope({
TypeA: {
"id?": "number",
typeB: modB.TypeB,
},
})
.export();
import {type} from "arktype";
import {modB} from "./testB";

export const modA = type
.scope({
TypeA: {
"id?": "number",
typeB: modB.TypeB,
},
})
.export();
testB.ts:
import {type} from "arktype";
import {modA} from "./testA";

export const modB = type
.scope({
TypeB: {
"id?": "number",
typeA: modA.TypeA,
},
})
.export();
import {type} from "arktype";
import {modA} from "./testA";

export const modB = type
.scope({
TypeB: {
"id?": "number",
typeA: modA.TypeA,
},
})
.export();
then i get an implicit any error on both (modA and modB) but if i put them in the same file and scope it works, why is that?
export const modC = type.scope({
TypeA: {
"id?": "number",
typeB: "TypeB",
},
TypeB: {
"id?": "number",
typeA: "TypeA",
},
})
export const modC = type.scope({
TypeA: {
"id?": "number",
typeB: "TypeB",
},
TypeB: {
"id?": "number",
typeA: "TypeA",
},
})
shouldnt that be the same? edit: i probably have to add that im new to arktype 😛 best regards 🙂
1 Reply
ssalbdivad
ssalbdivad•2mo ago
Hey! glad to have you here 😊 So whether TS can evaluate some cyclic relationship is usually going to have more to do with the nuances of the way their checker is implemented as opposed to be something arktype can control directly in a case like this. However, here it's probably not a bad thing this fails because if you think about what will happen at runtime, it's impossible for both scopes to resolve the types they need when being constructed. With a single scope, there's a parse step that allows cyclic types to be instantiated together. When a scope is defined and exported from a file, it needs to be able to parse the type from the other file, which can't have been instantiated yet.

Did you find this page helpful?