javascript - 得到“错误 TS2304:找不到名称”'` 与 ts-node 编译
问题描述
我有这个tsconfig.json
:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "ts",
"esModuleInterop": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types",
"./src/types"
]
},
"exclude": ["node_modues"]
}
我有这个文件夹结构:
src/
scripts/
doX.ts
types/
number.d.ts
在number.d.ts
我有:
type int8 = number
在doX.ts
中,我有:
function add8(a: int8, b: int8) {
return a + b
}
const x: int8 = add8(1, 2)
我在 VSCode 中没有收到任何错误,但是当我执行以下操作时出现错误:
$ 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) {
~~~~ ~~~~
我错过了什么ts-node
才能正确编译和运行它?
解决方案
推荐阅读
- java - 寻找正确的 JIRA Java SDK 版本的问题
- python - Android上的Appium + Python - 滚动不起作用
- java - 从列表中删除重复的对象,按字符串属性进行比较
- c - 在另一台 PC 上运行 C 构建的 .exe
- asp.net-core - GetService 与 ApplicationServices 和 IServiceProvider 有什么区别?
- python - 将自定义用户身份验证添加到 django-rest-framework-simple-jwt
- r - 不从源代码安装软件包的含义?
- r - 在 R 中查询 PostgreSQL 数据库时,如何修复警告消息“关闭打开的结果集,取消先前的查询”?
- java - 如何从 Web 读取 JSON 数据并将插入插入数据库
- ios - iOS VoiceOver 读取accessibilityIdentifier 而不是accessibilityLabel