错误TS2322:类型“字符串”不可分配给类型“ Ex1”

时间:2019-11-06 12:57:33

标签: typescript

代码:

enum Ex0 {
    One = '/home/node/',
    Two = '/home/node/'
}

enum Ex1 {
    One = path.normalize('~/'),
    Two = path.normalize('~/')
}

错误:

application/libs/config.ts:19:11 - error TS2322: Type 'string' is not assignable to type 'Ex1'.

19     One = path.normalize('~/'),
             ~~~~~~~~~~~~~~~~~~~~

application/libs/config.ts:20:11 - error TS2322: Type 'string' is not assignable to type 'Ex1'.

20     Two = path.normalize('~/')

由于缺乏好的文档,我在理解Typescript枚举时遇到问题。谁能解释我在这里做错了什么。 path.normalize返回类型string

0 个答案:

没有答案