Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import { JSXInternal } from '../../src/jsx';
import * as _Suspense from './suspense';
import * as _SuspenseList from './suspense-list';

interface SignalLike<T> {
value: T;
peek(): T;
subscribe(fn: (value: T) => void): () => void;
}

type Signalish<T> = T | SignalLike<T>;

// export default React;
export = React;
export as namespace React;
Expand Down Expand Up @@ -272,7 +264,7 @@ declare namespace React {
}

export function forwardRef<R, P = {}>(
fn: ForwardFn<P, R>
fn: ForwardRefRenderFunction<R, P>
Comment on lines -275 to +267
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from #4675 -- ForwardFn is not the name in React & notably it has the generics reversed. It was marked as deprecated in that PR so all this is doing is replacing it with the correct, non-deprecated version (the internals of both types match).

): preact.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact.Ref<R> }>;

export type PropsWithoutRef<P> = Omit<P, 'ref'>;
Expand Down
20 changes: 11 additions & 9 deletions hooks/src/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
Options as PreactOptions,
Component as PreactComponent,
VNode as PreactVNode,
Context as PreactContext,
PreactContext,
HookType,
ErrorInfo,
} from '../../src/internal';
import { Reducer, StateUpdater } from '.';

Expand Down Expand Up @@ -30,14 +32,14 @@ export interface ComponentHooks {
_pendingEffects: EffectHookState[];
}

export interface Component extends PreactComponent<any, any> {
export interface Component extends Omit<PreactComponent<any, any>, '_renderCallbacks'> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a healthy sprinkling of Omit which I think is correct given our use cases -- generally, our internal types intentionally clash with the base/user-exposed types.

__hooks?: ComponentHooks;
// Extend to include HookStates
_renderCallbacks?: Array<HookState | (() => void)>;
_hasScuFromHooks?: boolean;
}

export interface VNode extends PreactVNode {
export interface VNode extends Omit<PreactVNode, '_component'> {
_mask?: [number, number];
_component?: Component; // Override with our specific Component type
}
Expand All @@ -52,12 +54,12 @@ export type HookState =

interface BaseHookState {
_value?: unknown;
_nextValue?: undefined;
_pendingValue?: undefined;
_args?: undefined;
_pendingArgs?: undefined;
_component?: undefined;
_cleanup?: undefined;
_nextValue?: unknown;
_pendingValue?: unknown;
_args?: unknown;
_pendingArgs?: unknown;
_component?: unknown;
_cleanup?: unknown;
}
Comment on lines 55 to 63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is a more specific type than unknown which disallows some interfaces from extending these properties as they need to.


export type Effect = () => void | Cleanup;
Expand Down
9 changes: 7 additions & 2 deletions jsconfig-lint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"extends": "./jsconfig.json",
"include": ["src/**/*", "hooks/src/**/*"]
}
"include": [
"src/**/*",
"hooks/src/**/*",
"compat/**/*.d.ts",
"jsx-runtime/**/*.d.ts"
Comment on lines +6 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compat & jsx-runtime source & test files throw up some errors yet but I think it's worth linting their types at least as these are user-exposed. Will help guard against typos and what not

]
}
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"preact/*": ["./*"]
},
"target": "es5",
"noEmit": true
"noEmit": true,
"skipLibCheck": false
},
"exclude": ["**/node_modules/**", "**/dist/**", "coverage", "demo"]
}
4 changes: 2 additions & 2 deletions src/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export interface PreactElement extends preact.ContainerNode {
readonly style?: CSSStyleDeclaration;

// nextSibling required for inserting nodes
readonly nextSibling: ContainerNode | null;
readonly nextSibling: PreactElement | null;

// Used to match DOM nodes to VNodes during hydration. Note: doesn't exist
// on Text nodes
Expand Down Expand Up @@ -158,7 +158,7 @@ export interface VNode<P = {}> extends preact.VNode<P> {
_flags: number;
}

export interface Component<P = {}, S = {}> extends preact.Component<P, S> {
export interface Component<P = {}, S = {}> extends Omit<preact.Component<P, S>, 'base'> {
// When component is functional component, this is reset to functional component
constructor: ComponentType<P>;
state: S; // Override Component["state"] to not be readonly for internal use, specifically Hooks
Expand Down
Loading