Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'arktype/out/keywords/inference' or its corresponding type declarations. #1141

Closed
fortezhuo opened this issue Sep 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@fortezhuo
Copy link

I still playing with arktype and found this issue while emiting d.ts

import { scope } from "arktype";

// Scopes are collections of types that can reference each other.
export const types = scope({
  package: {
    name: "string",
    "dependencies?": "package[]",
    "contributors?": "contributor[]",
  },
  contributor: {
    // Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime.
    email: "string.email",
    "packages?": "package[]",
  },
}).export();

// Cyclic types are inferred to arbitrary depth...
export type Package = typeof types.package.infer;

// And can validate cyclic data.
const packageData: Package = {
  name: "arktype",
  dependencies: [{ name: "typescript" }],
  contributors: [{ email: "david@sharktypeio" }],
};
packageData.dependencies![0].dependencies = [packageData];

export const out = types.package(packageData);

d.ts result

export declare const types: import("arktype").Module<{
    package: {
        name: string;
        dependencies?: any[];
        contributors?: {
            email: string & {
                " arkConstrained": import("arktype/out/keywords/inference").Branded<"email">;
            };
            packages?: any[];
        }[];
    };
    contributor: {
        email: string & {
            " arkConstrained": import("arktype/out/keywords/inference").Branded<"email">;
        };
        packages?: any[];
    };
}>;
export type Package = typeof types.package.infer;
export declare const out: {
    name: string;
    dependencies?: any[];
    contributors?: {
        email: string;
        packages?: any[];
    }[];
} | import("arktype").ArkErrors;
image

tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "Node",
    "target": "ESNext",
    "skipLibCheck": true,
    "strict": true,
    "exactOptionalPropertyTypes": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "declarationDir": "./type"
  }
}
@fortezhuo fortezhuo added the bug Something isn't working label Sep 19, 2024
@ssalbdivad
Copy link
Member

It seems like you need moduleResolution: "NodeNext" to get TS to output the correct paths. Here is the config I used to test it:

{
    "compilerOptions": {
        "module": "NodeNext",
        "target": "ESNext",
        "moduleResolution": "NodeNext",
        "lib": ["ESNext"],
        "skipLibCheck": true,
        "declaration": true,
        "strict": true,
        "verbatimModuleSyntax": true,
        "esModuleInterop": true,
        "types": ["node"]
    },
    "include": ["src"]
}

That said, it seems like a limitation of TS that anonymous cyclic types can't be output as .d.ts, as I notice this was my output:

export declare const out: {
    name: string;
    dependencies?: any[] | undefined;
    contributors?: {
        email: string;
        packages?: any[] | undefined;
    }[] | undefined;
} | import("arktype").ArkErrors;

It makes sense they're not serializable directly, but may be worth opening an issue on the TS repo to see if there's another way.

@fortezhuo
Copy link
Author

fortezhuo commented Sep 28, 2024

I still found Argument of type 'string' is not assignable to parameter of type '(string & { " of": { base: string; attributes: MoreThanLength<7>; }; }) | (string & { " of": { base: string; attributes: MoreThanLength<7>; }; }) | (string & { ...; }) | (string & { ...; }) | undefined'.

But seems same issue with #1116 , so please refers to #1116 to maintain the issue solving

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done (merged or closed)
Development

No branches or pull requests

2 participants