I have this in my tsconfig.json
:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "ts",
"esModuleInterop": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types",
"./src/types"
]
},
"exclude": ["node_modues"]
}
I have this folder structure:
src/
scripts/
doX.ts
types/
number.d.ts
In number.d.ts
I have:
type int8 = number
In doX.ts
, I have:
function add8(a: int8, b: int8) {
return a + b
}
const x: int8 = add8(1, 2)
I am getting no errors in VSCode, but when I do the following I get an error:
$ npx ts-node src/scripts/doX.ts
? Unable to compile TypeScript:
src/scripts/doX.ts:... - error TS2304: Cannot find name 'int8'.
... function add(a: int8, b: int8) {
~~~~ ~~~~
What am I missing to get ts-node
to compile and run this properly?
question from:
https://stackoverflow.com/questions/65898800/getting-error-ts2304-cannot-find-name-type-with-ts-node-compilation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…