-
Notifications
You must be signed in to change notification settings - Fork 196
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
Auto generate index.d.ts by typescript #238
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added self-review. I can further cleanup the types to improve DX further.
@@ -55,7 +55,7 @@ yarn shortest | |||
headless: false, | |||
baseUrl: 'http://localhost:3000', | |||
testPattern: '**/*.test.ts', | |||
anthropicKey: process.env.ANTHROPIC_API_KEY | |||
anthropicKey: process.env.ANTHROPIC_API_KEY || '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now necessary as typescript is considering env vars as string | undefined
therefore we have to add an fallback empty string to silence typescript errors. As mentioned before we can have these managed internally without having users to declare these here.
@@ -72,7 +72,7 @@ You can also use callback functions to add additional assertions and other logic | |||
execution in browser is completed. | |||
|
|||
```typescript | |||
import { shortest } from '@antiwork/shortest'; | |||
import { shortest, expect } from '@antiwork/shortest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the main reasons why we created index.d.ts
manually was to allow users to use jestExpect without having to import it. With the new changes this is necessary.
@@ -5,28 +5,27 @@ | |||
"type": "module", | |||
"main": "./dist/index.js", | |||
"module": "./dist/index.js", | |||
"types": "./index.d.ts", | |||
"types": "./dist/types/index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading the autogenerated types instead of the file we created manually
], | ||
"scripts": { | ||
"build": "rm -rf dist && pnpm build:types && pnpm build:js && pnpm build:cli", | ||
"prepare": "pnpm build", | ||
"prepublishOnly": "pnpm build", | ||
"postinstall": "node -e \"if (process.platform !== 'win32') { try { require('child_process').execSync('chmod +x dist/cli/bin.js') } catch (_) {} }\"", | ||
"build:types": "tsc --emitDeclarationOnly --outDir dist/types && cp index.d.ts dist/", | ||
"build:types": "tsc --emitDeclarationOnly --outDir dist/types", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is in charge of generating the types.
@@ -227,6 +224,7 @@ export const test: TestAPI = Object.assign( | |||
}, | |||
); | |||
|
|||
export const expect = jestExpect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making jestExpect available as an import in the test files
|
||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
__shortest__: ShortestGlobals; | ||
} | ||
} | ||
} | ||
|
||
export {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of jest setup. we had it in index.d.ts
before but now we declare it here. This will get autogenerated by typescript.
anthropicKey: process.env.ANTHROPIC_API_KEY || "", | ||
mailosaur: { | ||
apiKey: process.env.MAILOSAUR_API_KEY, | ||
serverId: process.env.MAILOSAUR_SERVER_ID, | ||
apiKey: process.env.MAILOSAUR_API_KEY || "", | ||
serverId: process.env.MAILOSAUR_SERVER_ID || "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to do this otherwise typescript throws an error.
If the expect changes are necessary, would be good to do in its own PR. cc @amk-dev |
Would be good to resolve merge conflicts now that the other branch was merged. I personally don't think doing || "" is a great idea, it pollutes the README/config and looks quite ugly. I'm sure there's a more elegant solution. Importing |
I think for the env vars we can just have the user set them up in their .env file and we directly read them from there. I think Vercel AI SDK is like that. For expect I had to update it in this PR otherwise it would have introduced a bug to the package. Since we already have expect implemented, if a user upgrade their shortest, their implementation would be broken. If you don't think expect is necessary, I can delete the jestExpect implementation all together. |
Makes sense to me to remove it. |
the merged PR should take care of this.
the merged PR preserves the current behaviour. I don't belive there's any functional issues remaining after that PR was merged. now its any new changes you guys want to make. (eg: remove one major difference from this PR to the merged PR is the use of |
had a discussion in the last PR about this. after my PR merge, |
Just saw your PR. This PR is not required anymore as your solves it in a better way. |
This PR addresses issue #231
Changes
build:types
script to generate types using tscindex.ts
to importexpect