Skip to content

Commit 1f5f978

Browse files
authored
fix: CSSStyleName typescript
1 parent d5ca096 commit 1f5f978

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

svg.js.d.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44
// trick to keep reference to Array build-in type
55
declare class BuiltInArray<T> extends Array<T> {}
66

7-
// trick to have nice attribute list for CSS
8-
declare type CSSStyleName = Exclude<
9-
keyof CSSStyleDeclaration,
10-
'parentRule' | 'length'
11-
>
12-
137
// camelCase to kebab-case
14-
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}`
15-
? U extends Uncapitalize<U>
16-
? `${Lowercase<T>}${CamelToKebab<U>}`
17-
: `${Lowercase<T>}-${CamelToKebab<U>}`
18-
: S;
19-
20-
type ConvertKeysToKebab<T> = {
21-
[K in keyof T as CamelToKebab<K & string>]: T[K];
8+
declare type CamelToKebab<S extends string> = S extends `${infer T}${infer U}`
9+
? U extends Uncapitalize<U>
10+
? `${Lowercase<T>}${CamelToKebab<U>}`
11+
: `${Lowercase<T>}-${CamelToKebab<U>}`
12+
: S;
13+
14+
declare type ConvertKeysToKebab<T> = {
15+
[K in keyof T as CamelToKebab<K & string>]: T[K];
2216
};
2317

18+
declare type KebabCSSStyleDeclaration = ConvertKeysToKebab<CSSStyleDeclaration>
19+
20+
// trick to have nice attribute list for CSS
21+
declare type CSSStyleName = Exclude<
22+
keyof KebabCSSStyleDeclaration,
23+
'parent-rule' | 'length'
24+
>
2425

2526
// create our own style declaration that includes css vars
26-
interface CSSStyleDeclarationWithVars extends ConvertKeysToKebab<CSSStyleDeclaration> {
27+
interface CSSStyleDeclarationWithVars extends KebabCSSStyleDeclaration {
2728
[key: `--${string}`]: string
2829
}
2930

0 commit comments

Comments
 (0)