React 样式 TypeScript 类型
创建于:2025-07-26 15:06:11
|
更新于:2025-11-12 15:59:45

react-style 中自定义 css 变量,ts 警告。

通过扩展 csstype 类型。

import type * as CSS from 'csstype';
 
declare module 'csstype' {
  interface Properties {
    // Add a missing property
    WebkitRocketLauncher?: string;
 
    // Add a CSS Custom Property
    '--theme-color'?: 'black' | 'white';
 
    // Allow namespaced CSS Custom Properties
    [index: `--theme-${string}`]: any;
 
    // Allow any CSS Custom Properties
    [index: `--${string}`]: any;
 
    // ...or allow any other property
    [index: string]: any;
  }
}
我也是有底线的 🫠