小编eri*_*n20的帖子

本地JS文件的打字稿声明文件

我正在尝试在转换为Typescript的过程中为我们的Javascript文件添加类型。但是,我无法识别声明文件。

这是我的文件结构

  • js
    • Foo.js
  • 打字
    • oo
      • 索引
  • 索引
  • package.json
  • tsconfig.json

Foo.js

module.exports = function Foo() {
   return 'Bar';
 };
Run Code Online (Sandbox Code Playgroud)

索引

export = Foo;

declare function Foo(): string;
Run Code Online (Sandbox Code Playgroud)

索引

import Foo = require('./js/Foo')

console.log(Foo());
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
  "compilerOptions": {
    "typeRoots": ["./typings"],
    "target": "es5",
    "strict": true,
    "baseUrl": "./",
    "paths": {
      "*": ["typings/*"]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

package.json

{
  "name": "fail",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "tsc": "tsc"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "typescript": "^3.1.4"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是重现我的问题的回购

https://github.com/erisman20/typings_help

编辑:这是我得到的错误 …

javascript declaration type-declaration typescript declaration-files

5
推荐指数
1
解决办法
3015
查看次数