shortest icon indicating copy to clipboard operation
shortest copied to clipboard

fix: fix incorrect path for types in index.d.ts

Open amk-dev opened this issue 1 year ago • 7 comments

Fixs #191

Changes

Previously when the package is bundled, index.d.ts had incorrect paths for some imports. this makes the ShortestConfig from @antiwork/shortest not resolve properly.

here's the file structure of the published package ( i've removed irrelevent files from the tree )

@antiwork/shortest/
├── dist/
│   └── types/
│       └── types/
│           ├── config.d.ts
│           └── test.d.ts
└── index.d.ts

so the imports in index.d.ts had two wrong imports

  • ./dist/types/test
  • ./dist/types/config

both will not resolve, the correct paths are

  • ./dist/types/types/test
  • ./dist/types/types/config

this PR makes that update.

note: as discussed in the issue, there are room for improvement in the generation of index.d.ts. I'm gathering context for that. but since this is a rather important fix (imo). raising a PR.

amk-dev avatar Dec 27 '24 22:12 amk-dev

@amk-dev is attempting to deploy a commit to the Antiwork Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 27 '24 22:12 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
shortest ❌ Failed (Inspect) Dec 29, 2024 11:14am

vercel[bot] avatar Dec 27 '24 22:12 vercel[bot]

@amk-dev thanks for the PR. Once you have the conflicts resolved I will test your branch and let you know.

m2rads avatar Dec 27 '24 22:12 m2rads

just rebased.

amk-dev avatar Dec 27 '24 22:12 amk-dev

since the type for ShortestConfig is in effect, there are some type errors in shortest/shortest.config.ts, that's causing the CI to fail i think.

image

how do you want to handle it ?

@m2rads

amk-dev avatar Dec 27 '24 23:12 amk-dev

Why do we have a types folder within a types folder?

slavingia avatar Dec 28 '24 16:12 slavingia

Why do we have a types folder within a types folder?

the build:types command is building types for src into dist/types, src has another folder named types. so types/types becomes a thing.

instead of updating the index.d.ts like i did in this PR, may be we can just build the types into dist instead of dist/types, that would eliminate the double types path. but need to see if it breaks any other imports / overwrites something.

image

amk-dev avatar Dec 28 '24 20:12 amk-dev

I think this error is happening because in types/config.ts we are enforcing the anthropicApiKey to be string but the type for process.env.ANTHROPIC_API_KEY is string | undefined therefore typescript is now correctly identifying the type issue here. IMO we could just directly use process.env.ANTHROPIC_API_KEY inside client.ts file where our AI implementation exists. This would remove the need for end users to specify their API key in the config file. Sort of like nextjs AI sdk where it reads the API keys internally. Same with Mailosaur. @slavingia what do you think? If not then we can just update the types to be string | undefined or instruct ts to not be strict about this somehow.

image

since the type for ShortestConfig is in effect, there are some type errors in shortest/shortest.config.ts, that's causing the CI to fail i think.

image how do you want to handle it ?

@m2rads

m2rads avatar Dec 29 '24 11:12 m2rads

Makes sense to do for Anthropic API key. Mailosaur isn't causing an issue as optional so imo better to expose in the config.

slavingia avatar Dec 29 '24 13:12 slavingia

this was accidently closed when i removed the forked repo from my account not remembering this PR was open. let me know if i should reopen this. but if there are plans for #205 to auto generate index.d.ts, this PR is not needed.

I've shared some ideas on the same on #205 . not making a PR for that issue, because it was assigned to @m2rads.

amk-dev avatar Dec 30 '24 23:12 amk-dev