代码之家  ›  专栏  ›  技术社区  ›  user1795832

编译器无法识别自定义TS类型

  •  1
  • user1795832  · 技术社区  · 6 年前

    我有一份打字文件在 src/@types/yargs-interactive/index.d.ts 我为之创造的 https://github.com/nanovazquez/yargs-interactive .其内容如下:

    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;
    

    但是当我尝试导入它时,我得到的只是 Could not find a declaration file for module 'yargs-interactive' 错误。我已尝试更改tsconfig.json文件以添加 typeRoots src/@types 目录,但仍然找不到。当它在下面的时候它会识别它 node_modules/@types/yargs-interactive/index.d.ts .

    我在这里做错什么了?

    1 回复  |  直到 6 年前
        1
  •  3
  •   kingdaro    6 年前

    this issue comment, typeRoots path mapping

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