Closed
Description
tsconfig.json 配置
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"outDir": "dist",
"strict": true,
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
原文描述
第二个方法是使用 import type 语句,这个语句只能输入类型,不能输入正常接口。
// 正确
import type { A } from './a';
// 报错
import type { a } from './a';
上面示例中,import type 输入类型A
是正确的,但是输入正常接口a
就会报错。
实测
正常引入第二个语句 import type { a } from './a';
时不会报错, 作为类型使用时也能正常使用,作为非类型的值使用时才会报错。例如:
import type { a } from './2'
type C = typeof a //正常
import type { a } from './2'
let c = a //报错: "a" 是使用 "import type" 导入的,因此不能用作值。ts(1361)
Metadata
Metadata
Assignees
Labels
No labels