TypeScript 的字符串枚举 - “Type ... 不可分配给 type ..." [英] TypeScript's string enums - "Type ... is not assignable to type ..."

查看:17
本文介绍了TypeScript 的字符串枚举 - “Type ... 不可分配给 type ..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将 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:SMARTSmartSmartClientAppappmodelsprocess.model.ts  17  Active
Error TS2322  Type '"S"' is not assignable to type
'StepType'.   ClientApp (tsconfig
project)  Z:SMARTSmartSmartClientAppappmodelsprocess.model.ts  14  Active
Error TS2322  Type '"A"' is not assignable to type
'StepType'.   ClientApp (tsconfig
project)  Z:SMARTSmartSmartClientAppappmodelsprocess.model.ts  15  Active
Error TS2322  Type '"D"' is not assignable to type
'StepType'.   ClientApp (tsconfig
project)  Z:SMARTSmartSmartClientAppappmodelsprocess.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. }

I am using Visual Studio 2017 which claims TypeScript 2.4.0 is installed:

I searched through

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 的字符串枚举 - “Type ... 不可分配给 type ..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆