origeva
origeva

Reputation: 191

Typescript on VS Code shows type any instead of the correct type

I'm making a node library where it's important for me to have the types for consumers but for some reason when I import my class from outside src VS Code will replace types on hints of some of the functions to any or any[], it seems that it will only do that for complex types but why does it happen only outside src and why at all?

When I ctrl + hover, it does show the correct type on the hint, but still when filling in the parameters VS Code doesn't help at all with object variable names or union types

I tried exporting all the types used in the function from the main entry point (src/index.ts) but that doesn't seem to help.

Is that a vscode bug? Something I can do to fix it?

https://github.com/origeva/node-sponsorblock-api

Hovering one of the functions

Upvotes: 6

Views: 1435

Answers (1)

origeva
origeva

Reputation: 191

Enable the declaration files option in your tsconfig to generate .d.ts files that describe your types.

{
    "compilerOptions": {
        "declaration": true
    }
}

Visit the documentation for more info.

Upvotes: 1

Related Questions