mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
refactor(core)!: tighten constrained jsx boundary
This commit is contained in:
@@ -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'>();
|
||||
});
|
||||
});
|
||||
@@ -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] } & {};
|
||||
|
||||
Reference in New Issue
Block a user