我有一种
type Rating = 0 | 1 | 2 | 3 | 4 | 5 | number
现在我想做这样的事情.
let myRating:Rating = 4
let rate:number = myRating as number
如何将我的myRating
转换为number
原始类型?
它给我的错误是:
将"评级"类型转换为"编号"类型可能是错误的,因为两种类型都没有充分重叠.如果这是有意的,请先将表达式转换为"未知".ts(2352)
我已经经历了this次,但我想要的是它的反面
编辑:
tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"target": "es6",
"allowJs": true,
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"strict": true
},
"include": [
"src"
]
}
tsc版本:3.2.1