Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better intellisense for target, controlslist and type #400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 76 additions & 27 deletions packages/dom-expressions/src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,29 @@ export namespace JSX {
}

interface BoundEventHandler<
T,
E extends Event,
EHandler extends EventHandler<T, any> = EventHandler<T, E>,
T,
E extends Event,
EHandler extends EventHandler<T, any> = EventHandler<T, E>
> {
0: (
data: any,
...e: Parameters<EHandler>,
) => void;
0: (data: any, ...e: Parameters<EHandler>) => void;
1: any;
}
type EventHandlerUnion<
T,
E extends Event,
EHandler extends EventHandler<T, any> = EventHandler<T, E>,
EHandler extends EventHandler<T, any> = EventHandler<T, E>
> = EHandler | BoundEventHandler<T, E, EHandler>;

interface EventHandlerWithOptions<T, E extends Event, EHandler = EventHandler<T, E>>
extends AddEventListenerOptions {
extends AddEventListenerOptions {
handleEvent: EHandler;
}

type EventHandlerWithOptionsUnion<T, E extends Event, EHandler extends EventHandler<T, any> = EventHandler<T, E>> =
| EHandler
| EventHandlerWithOptions<T, E, EHandler>;
type EventHandlerWithOptionsUnion<
T,
E extends Event,
EHandler extends EventHandler<T, any> = EventHandler<T, E>
> = EHandler | EventHandlerWithOptions<T, E, EHandler>;

interface InputEventHandler<T, E extends InputEvent> {
(
Expand All @@ -65,7 +64,11 @@ export namespace JSX {
}
): void;
}
type InputEventHandlerUnion<T, E extends InputEvent> = EventHandlerUnion<T, E, InputEventHandler<T, E>>;
type InputEventHandlerUnion<T, E extends InputEvent> = EventHandlerUnion<
T,
E,
InputEventHandler<T, E>
>;

interface ChangeEventHandler<T, E extends Event> {
(
Expand All @@ -77,7 +80,11 @@ export namespace JSX {
}
): void;
}
type ChangeEventHandlerUnion<T, E extends Event> = EventHandlerUnion<T, E, ChangeEventHandler<T, E>>;
type ChangeEventHandlerUnion<T, E extends Event> = EventHandlerUnion<
T,
E,
ChangeEventHandler<T, E>
>;

interface FocusEventHandler<T, E extends FocusEvent> {
(
Expand All @@ -89,7 +96,11 @@ export namespace JSX {
}
): void;
}
type FocusEventHandlerUnion<T, E extends FocusEvent> = EventHandlerUnion<T, E, FocusEventHandler<T, E>>;
type FocusEventHandlerUnion<T, E extends FocusEvent> = EventHandlerUnion<
T,
E,
FocusEventHandler<T, E>
>;

const SERIALIZABLE: unique symbol;
interface SerializableAttributeValue {
Expand All @@ -102,9 +113,11 @@ export namespace JSX {
}
interface CustomAttributes<T> {
ref?: T | ((el: T) => void) | undefined;
classList?: {
[k: string]: boolean | undefined;
} | undefined;
classList?:
| {
[k: string]: boolean | undefined;
}
| undefined;
$ServerOnly?: boolean | undefined;
}
type Accessor<T> = () => T;
Expand Down Expand Up @@ -201,9 +214,11 @@ export namespace JSX {
"on:compositionstart"?: EventHandlerWithOptionsUnion<T, CompositionEvent> | undefined;
"on:compositionupdate"?: EventHandlerWithOptionsUnion<T, CompositionEvent> | undefined;
"on:focusout"?:
EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>>
| undefined;
"on:focusin"?:
EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>>
| undefined;
"on:encrypted"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:dragexit"?: EventHandlerWithOptionsUnion<T, DragEvent> | undefined;
}
Expand Down Expand Up @@ -377,10 +392,12 @@ export namespace JSX {
"on:animationstart"?: EventHandlerWithOptionsUnion<T, AnimationEvent> | undefined;
"on:auxclick"?: EventHandlerWithOptionsUnion<T, MouseEvent> | undefined;
"on:beforeinput"?:
EventHandlerWithOptionsUnion<T, InputEvent, InputEventHandler<T, InputEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, InputEvent, InputEventHandler<T, InputEvent>>
| undefined;
"on:beforetoggle"?: EventHandlerWithOptionsUnion<T, ToggleEvent> | undefined;
"on:blur"?:
EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>>
| undefined;
"on:canplay"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:canplaythrough"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:change"?: EventHandlerWithOptionsUnion<T, Event, ChangeEventHandler<T, Event>> | undefined;
Expand All @@ -399,10 +416,12 @@ export namespace JSX {
"on:ended"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:error"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:focus"?:
EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, FocusEvent, FocusEventHandler<T, FocusEvent>>
| undefined;
"on:gotpointercapture"?: EventHandlerWithOptionsUnion<T, PointerEvent> | undefined;
"on:input"?:
EventHandlerWithOptionsUnion<T, InputEvent, InputEventHandler<T, InputEvent>> | undefined;
| EventHandlerWithOptionsUnion<T, InputEvent, InputEventHandler<T, InputEvent>>
| undefined;
"on:invalid"?: EventHandlerWithOptionsUnion<T, Event> | undefined;
"on:keydown"?: EventHandlerWithOptionsUnion<T, KeyboardEvent> | undefined;
"on:keypress"?: EventHandlerWithOptionsUnion<T, KeyboardEvent> | undefined;
Expand Down Expand Up @@ -944,7 +963,7 @@ export namespace JSX {
ping?: string | undefined;
referrerpolicy?: HTMLReferrerPolicy | undefined;
rel?: string | undefined;
target?: string | undefined;
target?: "_self" | "_blank" | "_parent" | "_top" | (string & {}) | undefined;
type?: string | undefined;
referrerPolicy?: HTMLReferrerPolicy | undefined;
}
Expand Down Expand Up @@ -1106,7 +1125,31 @@ export namespace JSX {
size?: number | string | undefined;
src?: string | undefined;
step?: number | string | undefined;
type?: string | undefined;
type?:
| "button"
| "checkbox"
| "color"
| "date"
| "datetime-local"
| "email"
| "file"
| "hidden"
| "image"
| "month"
| "number"
| "password"
| "radio"
| "range"
| "reset"
| "search"
| "submit"
| "tel"
| "text"
| "time"
| "url"
| "week"
| (string & {})
| undefined;
value?: string | string[] | number | undefined;
width?: number | string | undefined;
crossOrigin?: HTMLCrossorigin | undefined;
Expand Down Expand Up @@ -1163,7 +1206,13 @@ export namespace JSX {
interface MediaHTMLAttributes<T> extends HTMLAttributes<T> {
autoplay?: boolean | undefined;
controls?: boolean | undefined;
controlslist?: string | undefined;
controlslist?:
| "nodownload"
| "nofullscreen"
| "noplaybackrate"
| "noremoteplayback"
| (string & {})
| undefined;
crossorigin?: HTMLCrossorigin | undefined;
loop?: boolean | undefined;
mediagroup?: string | undefined;
Expand Down