refactor(core)!: tighten constrained jsx boundary

This commit is contained in:
Rahim
2026-06-20 15:37:34 -07:00
parent 5fcab69d34
commit 99613ad768
31 changed files with 314 additions and 400 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
import type { StringWithSuggestions } from '../types';
// Method syntax is required here for TypeScript's class inheritance checking.
// Using property syntax (e.g., `connectedCallback?: () => void`) causes TS2425
// when a class extends a generic mixin that defines lifecycle callbacks.
@@ -18,7 +20,7 @@ export type QueriedElement<S extends string, E extends Element> = S extends keyo
? HTMLElementTagNameMap[S]
: E;
export type EventType<Events> = (keyof Events & string) | (string & {});
export type EventType<Events> = StringWithSuggestions<keyof Events & string>;
export type EventListenerFor<Events, K> =
| ((event: K extends keyof Events ? Events[K] : Event) => void)
@@ -0,0 +1,12 @@
import { describe, expectTypeOf, it } from 'vitest';
import type { StringWithSuggestions } from '../types';
describe('StringWithSuggestions', () => {
it('accepts arbitrary strings without widening literal unions', () => {
type Action = StringWithSuggestions<'play' | 'pause'>;
expectTypeOf<Action>().toMatchTypeOf<string>();
expectTypeOf<string>().toMatchTypeOf<Action>();
expectTypeOf<Extract<Action, 'play'>>().toEqualTypeOf<'play'>();
});
});
+2
View File
@@ -15,6 +15,8 @@ export type MixinReturn<Base extends AnyConstructor<any>, Props> = Constructor<I
export type Falsy<T> = T | false | null | undefined;
export type StringWithSuggestions<Value extends string> = Value | (string & {});
export type EnsureFunction<T> = T extends (...args: any[]) => any ? T : never;
export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};