我有这个代码:
Error.prepareStackTrace = function (
error: Error,
stack: Array<CallSite>,
) {
return self.parse(fiber, error, stack)
}
我正在尝试导入CallSite
,但在@types/node
中找不到它。
tsconfig.json
{
"compilerOptions": {
"module": "ES6",
"target": "ES6",
"lib": ["es2020"],
"outDir": "host",
"rootDir": "make",
"sourceMap": true,
"moduleResolution": "node",
"strictNullChecks": true,
"strict": true,
"esModuleInterop": true,
"noUncheckedIndexedAccess": true,
"baseUrl": "./make",
"paths": {
"~": ["."]
},
"types": ["node"],
"typeRoots": ["node_modules/@types"],
"noImplicitAny": true
},
"include": ["make"],
"exclude": ["node_modules"]
}
package.json
{
"type": "module",
"scripts": {
"build": "tsc && tsc-alias",
"watch": "concurrently --kill-others \"tsc -w\" \"tsc-alias -w\"",
"lint": "eslint --ext .ts ./make",
"lint:fix": "npm run lint -- --fix",
"test": "node --no-warnings --loader @esbuild-kit/esm-loader host/build"
},
"devDependencies": {
...
"@types/node": "^18.11.17",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.2",
"typescript": "^4.9.4"
}
}
你知道为什么它找不到它,或者怎么找到它吗?
1条答案
按热度按时间lsmepo6l1#
如果检查源代码,
CallSite
位于名称空间NodeJS
中。https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0cb820adf9389fbda935c850f58eb2c5e5973515/types/node/globals.d.ts#L125
所以你需要像这样修改你的声明。