简体   繁体   English

如何测试 typescript 声明文件是否针对本地 js 库编译

[英]How to test that typescript declaration files compile against local js library

I've added typescript definitions to HunterLarco/twitter-v2 which has the structure:我已将 typescript 定义添加到具有以下结构的HunterLarco/twitter-v2中:

package.json
src/
  twitter.js
  twitter.d.ts
  Credentials.js
  Credentials.d.ts

and I'd like to test that .js files match the .d.ts declaration files.我想测试.js文件是否与.d.ts声明文件匹配。

Current Progress现在的进展

Right now I'm using this tsconfig.json现在我正在使用这个tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "baseUrl": ".",
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2018"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "paths": { "twitter-v2": ["src"] },
    "typeRoots": [
      "./node_modules/@types",
      "./src"
    ],
    "outDir": "dist",
    "strict": true,
    "target": "es2018"
  },

  "include": [
    "src/**/*",
    "tests/**/*"
  ]
}

but when I intentionally add incorrect type information to twitter.d.ts and run tsc --project tsconfig.json it reports no errors and writes to dist/ .但是当我故意将不正确的类型信息添加到twitter.d.ts并运行tsc --project tsconfig.json时,它不会报告任何错误并写入dist/

I needed to enable the compiler option to check js files (which typescript does not do by default even with js is allowed)我需要启用编译器选项来检查 js 文件(即使允许使用 js,typescript 默认情况下也不会这样做)

https://www.typescriptlang.org/tsconfig#checkJs https://www.typescriptlang.org/tsconfig#checkJs

{
  "extends": "@tsconfig/node10/tsconfig.json",

  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "checkJs": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true
  },

  "include": ["src/**/*", "tests/**/*"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM