user1795832
user1795832

Reputation: 2160

Custom TS typings not being recognized by compiler

I have a typings file at src/@types/yargs-interactive/index.d.ts that I created for https://github.com/nanovazquez/yargs-interactive. It's contents are as follows:

declare function yargsInteractive(): any;

declare namespace yargsInteractive {
  interface OptionData {
    type: string;
    describe: string;
    default?: string | number | boolean;
    prompt?: string;
  }

  interface Option {
    [key: string]: OptionData;
  }

  interface Interactive {
    usage(usage: string): any;
    interactive(options: Option[]): any;
    then(callback: (result: any) => any): any;
  }
}

export = yargsInteractive;

However when I try importing it, all I get is a Could not find a declaration file for module 'yargs-interactive' error. I've tried changing my tsconfig.json file to add typeRoots to the src/@types directory, but it still doesn't find it. It recognizes it when it's under node_modules/@types/yargs-interactive/index.d.ts.

What am I doing wrong here?

Upvotes: 2

Views: 830

Answers (1)

kingdaro
kingdaro

Reputation: 12018

According to this issue comment, typeRoots was meant for using globally-available types, not those that should be imported. Try using a path mapping instead:

{
  "compilerOptions": {
    "baseUrl": ".", // baseUrl is required for paths to work
    "paths": {
      "*": ["src/@types/*"]
    },
    // other options...

Upvotes: 5

Related Questions