为什么字符串模板没有通过 CI

Why String Templates do not pass CI

我的程序完全可以运行,但是 CI 在以下位置失败:

export interface FC
{
  offset: `${number}%`;
  ..
}

它声称 TypeScript error: Type expected。为什么?

您要找的是Template Literal Types。但是,它仅适用于 TypeScript >= 4.1

您应该在 package.json 中更新您的 TypeScript 版本。

在那之后,它肯定会起作用:

export interface FC
{
  offset: `${number}%`;
}

let valid: FC = {
  offset: '1%'
}

let invalid: FC = {
  offset: '1'
}

Playground link