代码之家  ›  专栏  ›  技术社区  ›  Martin Nuc

为什么在使用Typescript时不需要节点的类型定义?

  •  0
  • Martin Nuc  · 技术社区  · 6 年前

    当我在Typescript中使用nodejs时,它允许我使用nodejs中的模块(比如 fs @types/node .

    1 回复  |  直到 6 年前
        1
  •  1
  •   fjc    6 年前

    它确实需要 @types/node :

    echo "import * fs fs from 'fs';" > test.ts
    tsc test.ts
    

    结果

    test.ts:1:21 - error TS2307: Cannot find module 'fs'.
    
    1 import * as fs from 'fs';
    

    然后做一个

    npm install @types/node
    tsc test.ts
    

    您是否可能全局安装了@types/node?

        2
  •  0
  •   Benny Code    4 年前

    当您使用的依赖项已经依赖于 @types/node @类型/节点 因为它是被吊起来的。

    yarn why @types/node ,它将显示有关 why a package is installed .