-
Notifications
You must be signed in to change notification settings - Fork 6
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
tweaks for satisfying typechecker #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -660,4 +660,4 @@ function effect(compute: () => unknown): () => void { | |
return effect._dispose.bind(effect); | ||
} | ||
|
||
export { signal, computed, effect, batch, Signal, ReadonlySignal }; | ||
export { signal, computed, effect, batch, Signal, type ReadonlySignal }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the identifiers exported on this line are both types and values, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I didn't know about this before. A bit more from ChatGPT:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,29 @@ const HAS_PENDING_UPDATE = 1 << 0; | |
const HAS_HOOK_STATE = 1 << 1; | ||
const HAS_COMPUTEDS = 1 << 2; | ||
|
||
const enum OptionsTypes { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I goofed on my previous pr (#7) and put these types after the code that uses them, which TypeScript doesn't like. |
||
HOOK = "_hook", | ||
DIFF = "_diff", | ||
DIFFED = "diffed", | ||
RENDER = "_render", | ||
CATCH_ERROR = "_catchError", | ||
UNMOUNT = "unmount", | ||
} | ||
|
||
interface OptionsType { | ||
[OptionsTypes.HOOK](component: Component, index: number, type: number): void; | ||
[OptionsTypes.DIFF](vnode: VNode): void; | ||
[OptionsTypes.DIFFED](vnode: VNode): void; | ||
[OptionsTypes.RENDER](vnode: VNode): void; | ||
[OptionsTypes.CATCH_ERROR](error: any, vnode: VNode, oldVNode: VNode): void; | ||
[OptionsTypes.UNMOUNT](vnode: VNode): void; | ||
} | ||
|
||
type HookFn<T extends keyof OptionsType> = ( | ||
old: OptionsType[T], | ||
...a: Parameters<OptionsType[T]> | ||
) => ReturnType<OptionsType[T]>; | ||
|
||
// Install a Preact options hook | ||
function hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) { | ||
// @ts-ignore-next-line private options hooks usage | ||
|
@@ -418,26 +441,3 @@ export function update<T extends SignalOrReactive>( | |
} | ||
} | ||
*/ | ||
|
||
const enum OptionsTypes { | ||
HOOK = "_hook", | ||
DIFF = "_diff", | ||
DIFFED = "diffed", | ||
RENDER = "_render", | ||
CATCH_ERROR = "_catchError", | ||
UNMOUNT = "unmount", | ||
} | ||
|
||
interface OptionsType { | ||
[OptionsTypes.HOOK](component: Component, index: number, type: number): void; | ||
[OptionsTypes.DIFF](vnode: VNode): void; | ||
[OptionsTypes.DIFFED](vnode: VNode): void; | ||
[OptionsTypes.RENDER](vnode: VNode): void; | ||
[OptionsTypes.CATCH_ERROR](error: any, vnode: VNode, oldVNode: VNode): void; | ||
[OptionsTypes.UNMOUNT](vnode: VNode): void; | ||
} | ||
|
||
type HookFn<T extends keyof OptionsType> = ( | ||
old: OptionsType[T], | ||
...a: Parameters<OptionsType[T]> | ||
) => ReturnType<OptionsType[T]>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { SwitchProps, Switch, ToggleProps, Toggle, DiamondToggle } from "./Toggle" | ||
export { ListboxProps, Listbox, SelectProps, Select } from "./Select" | ||
export { type SwitchProps, Switch, type ToggleProps, Toggle, DiamondToggle } from "./Toggle" | ||
export { type ListboxProps, Listbox, type SelectProps, Select } from "./Select" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freeGlobal
is inferred to have a type offalse | typeof globalThis
, so we need to ensure thatfreeGlobal
isn'tfalse
before checking its properties.