Typescript d.ts文件是如何作用的

我的文件目录是这样的
image.png

add.js

export const add = (a, b) => a + b

add.d.ts

export declare type add = (a: string, b: string) => string;

index.ts

import { add } from "./add";

const a = add('11', '11')

在index中引入时会报错,编辑器误将add仅仅当作一个type
image.png

我在tsconfig里也配置了

{
  "compilerOptions": {
    "outDir": "lib",
    "module": "esnext",
    "target": "es6",
    "declaration": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "typeRoots": ["./node_modules/@types", "./src/add/add.d.ts"]
  },
  "include": ["src"],
  "exclude": []
}

是哪里出了问题呢

阅读 1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题