From: 夜 <951540966@qq.com> Date: Wed, 17 Jul 2024 06:15:50 +0000 (+0800) Subject: fix: CSSStyleName typescript X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1321%2Fhead;p=svg.js.git fix: CSSStyleName typescript --- diff --git a/svg.js.d.ts b/svg.js.d.ts index c731b25..b3f17e9 100644 --- a/svg.js.d.ts +++ b/svg.js.d.ts @@ -4,26 +4,27 @@ // trick to keep reference to Array build-in type declare class BuiltInArray extends Array {} -// trick to have nice attribute list for CSS -declare type CSSStyleName = Exclude< - keyof CSSStyleDeclaration, - 'parentRule' | 'length' -> - // camelCase to kebab-case -type CamelToKebab = S extends `${infer T}${infer U}` - ? U extends Uncapitalize - ? `${Lowercase}${CamelToKebab}` - : `${Lowercase}-${CamelToKebab}` - : S; - -type ConvertKeysToKebab = { - [K in keyof T as CamelToKebab]: T[K]; +declare type CamelToKebab = S extends `${infer T}${infer U}` + ? U extends Uncapitalize + ? `${Lowercase}${CamelToKebab}` + : `${Lowercase}-${CamelToKebab}` + : S; + +declare type ConvertKeysToKebab = { + [K in keyof T as CamelToKebab]: T[K]; }; +declare type KebabCSSStyleDeclaration = ConvertKeysToKebab + +// trick to have nice attribute list for CSS +declare type CSSStyleName = Exclude< + keyof KebabCSSStyleDeclaration, + 'parent-rule' | 'length' +> // create our own style declaration that includes css vars -interface CSSStyleDeclarationWithVars extends ConvertKeysToKebab { +interface CSSStyleDeclarationWithVars extends KebabCSSStyleDeclaration { [key: `--${string}`]: string }