export enum JobType {
'A' = 'A',
'B' = 'B',
'C' = 'C',
}
type RecipeObj = {
job: JobType,
input: {[key: string]: number},
output: {[key: string]: number}
}
let recipe: RecipeObj = {
job: JobType.A,
input: {},
output: {},
};
错误:在TS2322: Type 'string' is not assignable to type enum
中将JobType.A
分配给job
时发生recipe
。提供了一个提示:The expected type comes from property 'job' which is declared here on type 'RecipeObj'
,但我不明白在这种情况下它的用处。
编辑:在JobType.A
后固定逗号。我没有收到与您相同的错误,但是您在JobType.A
之后缺少逗号。