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

Some types not resolvable transitively when published to .d.ts #1116

Closed
SynthLuvr opened this issue Sep 2, 2024 · 6 comments
Closed

Some types not resolvable transitively when published to .d.ts #1116

SynthLuvr opened this issue Sep 2, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@SynthLuvr
Copy link

Report a bug

πŸ”Ž Search Terms

🧩 Context

  • ArkType version: 2.0.0-dev.29
  • TypeScript version (5.1+): 5.5.4
  • Other context you think may be relevant (JS flavor, OS, etc.):

πŸ§‘β€πŸ’» Repro

Create a simple type like:

import { type } from "arktype";

const Address = type("string").narrow(() => true);
type Address = typeof Address.in.infer;

export { Address }

When used in TypeScript code, Address will resolve to type string. When compiled down into JavaScript, the d.ts file looks like:

declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;

Now Address resolves to any.

@SynthLuvr SynthLuvr added the bug Something isn't working label Sep 2, 2024
@ssalbdivad ssalbdivad removed the bug Something isn't working label Sep 15, 2024
@ssalbdivad ssalbdivad changed the title Compiling from TypeScript to JavaScript results in type any Some types not resolvable transitively when published to .d.ts Sep 15, 2024
@ssalbdivad ssalbdivad added the enhancement New feature or request label Sep 15, 2024
@ssalbdivad
Copy link
Member

Similar resolution issues can occur when building schemas from other validators.

I do want to look into strategies for avoiding this so that I can minimize cases where it occurs and give advice about how to work around the others, but this isn't a bug with ArkType. If anything, you could log a TypeScript bug describing how .d.ts output paths aren't always resolvable, but there must be a slew of those.

@ssalbdivad
Copy link
Member

Is it possible your moduleResolution is set to something old like "node"?

I wasn't able to reproduce this with modern tsconfig settings. Theoretically, "node" is supported directly, but without exposing the whole API at the top-level of my package, I'm not sure how I could support it for these kinds of transitive resolutions.

See #1141

@SynthLuvr
Copy link
Author

I'm using "moduleResolution": "NodeNext", and it's still resolving types to any

@ssalbdivad
Copy link
Member

You will have to provide a repo or branch with a resolution. I tried to repro with the settings mentioned in the other issue and TS correctly serialized the output path as arktype/internal/...

@SynthLuvr
Copy link
Author

Updated arktype and now getting a new error:

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'.

This should just be simplified to string?

@SynthLuvr
Copy link
Author

Ok got it working with a few hacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done (merged or closed)
Development

No branches or pull requests

2 participants