首页 > 解决方案 > 运行新类型定义的测试时出现“错误:未使用的文件”

问题描述

我在DefinitelyTyped项目中为连字符库创建了一个新的类型定义。你可以在这里看到它。

但是,在运行测试脚本时,npm run test hyphen我收到以下错误消息:

C:\MyProjects\code\ts-d.ts\DefinitelyTyped>npm run test hyphen

> definitely-typed@0.0.3 test C:\MyProjects\code\ts-d.ts\DefinitelyTyped
> node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed "hyphen"

Clean data
Clean logs
Clean output
Using local Definitely Typed at C:\MyProjects\code\ts-d.ts\DefinitelyTyped.
Parsing definitions...
Found 6695 packages.
Parsing in parallel...
Error: Unused file C:\MyProjects\code\ts-d.ts\DefinitelyTyped/types/hyphen/index.d.ts (used files: ["patterns/de-1996.d.ts","patterns/hu.d.ts","en-gb.d.ts","hyphen-tests.ts","common.ts","tsconfig.json","tslint.json"])
    at checkAllUsedRecur (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser.js:368:23)
    at checkAllFilesUsed (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser.js:331:5)
    at getTypingDataForSingleTypesVersion (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser.js:142:5)
    at combineDataForAllTypesVersions (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser.js:96:25)
    at Object.getTypingInfo (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser.js:27:82)
    at C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser-worker.js:17:50
    at Object.logUncaughtErrors (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\util\util.js:78:38)
    at process.<anonymous> (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\lib\definition-parser-worker.js:15:16)
    at process.emit (events.js:210:5)
    at emit (internal/child_process.js:876:12)
Error: Parsing failed.
    at fail (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\util\util.js:272:20)
    at ChildProcess.<anonymous> (C:\MyProjects\code\ts-d.ts\DefinitelyTyped\node_modules\types-publisher\bin\util\util.js:261:21)
    at ChildProcess.emit (events.js:210:5)
    at finish (internal/child_process.js:861:14)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

错误说这index.d.ts是一个未使用的文件。但这不是真的,因为它在我的hyphen-tests.ts文件中使用。

我可以添加index.d.tsOTHER_FILES.txt绕过问题,但这显然不是正确的解决方案。有人可以帮我吗?提前致谢。

标签: typescriptdefinitelytyped.d.ts

解决方案


我发现我错过了我的选项中的index.d.ts条目:filestsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "lib": [
            "es6"
        ],
        "strict": true,
        "baseUrl": "../",
        "typeRoots": [
            "../"
        ],
        "noEmit": true,
        "forceConsistentCasingInFileNames": true,
        "types": []
    },
    "files": [
        "index.d.ts",
        "hyphen-tests.ts"
    ]
}

但我仍然不知道为什么它必须在那里,因为所有其他.d.ts文件都是通过它们各自在hyphen-tests.ts.


推荐阅读