Skip to content

Commit 2a788d6

Browse files
authored
chore: Fix TS lang server support in our .d.ts files (#4698)
* chore: Fix TS lang server support in our `.d.ts` files * refactor: Fix internal types issues * refactor: Fix a couple compat types whilst we're at it * chore: Lint compat & jsx-runtime types too
1 parent 8941185 commit 2a788d6

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

compat/src/index.d.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ import { JSXInternal } from '../../src/jsx';
66
import * as _Suspense from './suspense';
77
import * as _SuspenseList from './suspense-list';
88

9-
interface SignalLike<T> {
10-
value: T;
11-
peek(): T;
12-
subscribe(fn: (value: T) => void): () => void;
13-
}
14-
15-
type Signalish<T> = T | SignalLike<T>;
16-
179
// export default React;
1810
export = React;
1911
export as namespace React;
@@ -272,7 +264,7 @@ declare namespace React {
272264
}
273265

274266
export function forwardRef<R, P = {}>(
275-
fn: ForwardFn<P, R>
267+
fn: ForwardRefRenderFunction<R, P>
276268
): preact.FunctionalComponent<PropsWithoutRef<P> & { ref?: preact.Ref<R> }>;
277269

278270
export type PropsWithoutRef<P> = Omit<P, 'ref'>;

hooks/src/internal.d.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
Options as PreactOptions,
33
Component as PreactComponent,
44
VNode as PreactVNode,
5-
Context as PreactContext,
5+
PreactContext,
6+
HookType,
7+
ErrorInfo,
68
} from '../../src/internal';
79
import { Reducer, StateUpdater } from '.';
810

@@ -30,14 +32,14 @@ export interface ComponentHooks {
3032
_pendingEffects: EffectHookState[];
3133
}
3234

33-
export interface Component extends PreactComponent<any, any> {
35+
export interface Component extends Omit<PreactComponent<any, any>, '_renderCallbacks'> {
3436
__hooks?: ComponentHooks;
3537
// Extend to include HookStates
3638
_renderCallbacks?: Array<HookState | (() => void)>;
3739
_hasScuFromHooks?: boolean;
3840
}
3941

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

5355
interface BaseHookState {
5456
_value?: unknown;
55-
_nextValue?: undefined;
56-
_pendingValue?: undefined;
57-
_args?: undefined;
58-
_pendingArgs?: undefined;
59-
_component?: undefined;
60-
_cleanup?: undefined;
57+
_nextValue?: unknown;
58+
_pendingValue?: unknown;
59+
_args?: unknown;
60+
_pendingArgs?: unknown;
61+
_component?: unknown;
62+
_cleanup?: unknown;
6163
}
6264

6365
export type Effect = () => void | Cleanup;

jsconfig-lint.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"extends": "./jsconfig.json",
3-
"include": ["src/**/*", "hooks/src/**/*"]
4-
}
3+
"include": [
4+
"src/**/*",
5+
"hooks/src/**/*",
6+
"compat/**/*.d.ts",
7+
"jsx-runtime/**/*.d.ts"
8+
]
9+
}

jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"preact/*": ["./*"]
1414
},
1515
"target": "es5",
16-
"noEmit": true
16+
"noEmit": true,
17+
"skipLibCheck": false
1718
},
1819
"exclude": ["**/node_modules/**", "**/dist/**", "coverage", "demo"]
1920
}

src/internal.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface PreactElement extends preact.ContainerNode {
109109
readonly style?: CSSStyleDeclaration;
110110

111111
// nextSibling required for inserting nodes
112-
readonly nextSibling: ContainerNode | null;
112+
readonly nextSibling: PreactElement | null;
113113

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

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

0 commit comments

Comments
 (0)