【发布时间】:2023-01-14 11:27:35
【问题描述】:
按预期工作:
interface ExampleA {
id: number;
name: `S${string}`;
}
export const exampleA = {
id: 8455,
name: 'Savory'
} as const satisfies ExampleA;
不起作用:-(
interface ExampleB {
id: number;
name: `S${string}`;
}
export const exampleB = [
{
id: 8455,
name: 'Savory'
}
] as const satisfies ExampleB[];
例如 B 的错误:
Type 'readonly [{ readonly id: 8455; readonly name: "Savory"; }]' does not satisfy the expected type 'ExampleB[]'.
The type 'readonly [{ readonly id: 8455; readonly name: "Savory"; }]' is 'readonly' and cannot be assigned to the mutable type 'ExampleB[]'.ts(1360)
我阅读了 TypeScript 4.9 博客文章和来自 TypeScript 存储库的几个 GitHub 问题,但仍然不知道我做错了什么,或者是否有其他方法可以做我想做的事情。
【问题讨论】:
标签: typescript