TypeScript的字符串枚举

编程入门 行业动态 更新时间:2024-10-27 19:21:03
本文介绍了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的字符串枚举

本文发布于:2023-11-14 02:34:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   TypeScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!