Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

javascript - Getting `error TS2304: Cannot find name '<type>'` with ts-node compilation

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...