TypeScript的字符串枚举-“类型...不可分配给类型..." [英] TypeScript's string enums - "Type ... is not assignable to type ..."
本文介绍了TypeScript的字符串枚举-“类型...不可分配给类型..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近将TypeScript的版本从2.3.4升级到了2.4.0,希望使用
I have recently upgraded the version of TypeScript from 2.3.4 to 2.4.0 hoping to use the string enums. To my dismay, however, I have been greeted with the error messages:
Severity Code Description Project File Line Suppression State
Error TS2322 Type '"E"' is not assignable to type
'StepType'. ClientApp (tsconfig
project) Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts 17 Active
Error TS2322 Type '"S"' is not assignable to type
'StepType'. ClientApp (tsconfig
project) Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts 14 Active
Error TS2322 Type '"A"' is not assignable to type
'StepType'. ClientApp (tsconfig
project) Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts 15 Active
Error TS2322 Type '"D"' is not assignable to type
'StepType'. ClientApp (tsconfig
project) Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts 16 Active
错误消息适用于以下代码段(带有行号):
The error messages apply to the following code snippet (with the line numbers):
13. export enum StepType {
14. Start = 'S',
15. Activity = 'A',
16. Decision = 'D',
17. End = 'E'
18. }
我正在使用Visual Studio 2017,它声称已安装TypeScript 2.4.0:
I am using Visual Studio 2017 which claims TypeScript 2.4.0 is installed:
我搜索了
解决此问题的方法是下载并安装 TypeScript 2.4 SDK ,然后从选项中选择较新的版本:
The way to resolve the issue was to download and install TypeScript 2.4 SDK and then select from the options the newer version:
这篇关于TypeScript的字符串枚举-“类型...不可分配给类型..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文