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

Can't resolve types #6022

Closed
dongnaebi opened this issue May 19, 2024 · 8 comments · Fixed by #6051
Closed

Can't resolve types #6022

dongnaebi opened this issue May 19, 2024 · 8 comments · Fixed by #6051

Comments

@dongnaebi
Copy link
Contributor

I am using RxDB in TypeScript, but I'm not getting any type hints. I looked in dist/types/index.d.ts and found this code:

export * from './plugin.ts';
export * from './rx-database.ts';
export * from './rx-error.ts';
export * from './rx-database-internal-store.ts';
// ...

It seems that the file names are incorrect. They should be xxx.d.ts?

@pubkey
Copy link
Owner

pubkey commented May 23, 2024

I am not sure if I understood your problem. But there are several unit tests that ensure these things work. For example in the angular RxDB example.

@dongnaebi
Copy link
Contributor Author

My point is: the types specified in package.json are ./dist/types/index.d.ts, but the file names exporting these types in ./dist/types/index.d.ts are incorrect, causing the editor(e.g. webstorm) to be unable to find these files, as shown in the picture:

image

@pubkey
Copy link
Owner

pubkey commented May 23, 2024

Can you make a PR with a proposed fix?

@dongnaebi
Copy link
Contributor Author

OK, I think for now, the most cost-effective solution is to directly replace the content of index.d.ts

// scripts/fix-type.mjs
import { promises as fs } from 'node:fs'

async function main () {
    const file = './dist/types/index.d.ts'
    try {
        let content = await fs.readFile(file, { encoding: 'utf-8' })
        content = content.replaceAll('export *', 'export type *').replaceAll('.ts', '.d.ts')
        await fs.writeFile(file, content)
    } catch (err) {
        console.log(`Fix type error:${err.message}`)
    }
}
main()

package.json

{
  "scripts": {
-     "build:types": "npm run build:version && rimraf -rf --max-retries=3 ./dist/types && tsc --project ./config/tsconfig.types.json && cp -r ./src/types ./dist/types/types",
+     "build:types": "npm run build:version && rimraf -rf --max-retries=3 ./dist/types && tsc --project ./config/tsconfig.types.json && cp -r ./src/types ./dist/types/types && node ./scripts/fix-type.mjs",
  }
}

@pubkey
Copy link
Owner

pubkey commented May 24, 2024

Does your webstorm auto import work correctly with this?

@dongnaebi
Copy link
Contributor Author

Yes, it's work for me

image

@pubkey
Copy link
Owner

pubkey commented May 25, 2024

@dongnaebi Thank you for the screenshot.
Can you make a PR with your proposed changes?

@dongnaebi
Copy link
Contributor Author

I'd be pleased to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants