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

chore: Fix TS lang server support in our .d.ts files #4698

Merged
merged 4 commits into from
Feb 19, 2025
Merged

Conversation

rschristian
Copy link
Member

Long been a bit of a headache, we don't get an TS support in our .d.ts files which allows typos, usused values, etc. to run a bit rampant. Turns out it's a simple issue: jsconfig.json has skipLibCheck set to false by default, and this is seemingly undocumented.

Easy fix and has surfaced a few (internal) errors already.

@@ -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.

@coveralls
Copy link

coveralls commented Feb 19, 2025

Coverage Status

coverage: 99.609%. remained the same
when pulling e0afeeb on chore/ts-files
into 8941185 on main.

Comment on lines 55 to 63
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;
}
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.

@rschristian rschristian marked this pull request as ready for review February 19, 2025 08:17
Comment on lines +6 to +7
"compat/**/*.d.ts",
"jsx-runtime/**/*.d.ts"
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

Comment on lines -275 to +267
fn: ForwardFn<P, R>
fn: ForwardRefRenderFunction<R, P>
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).

@rschristian rschristian merged commit 2a788d6 into main Feb 19, 2025
5 checks passed
@rschristian rschristian deleted the chore/ts-files branch February 19, 2025 08:47
@JoviDeCroock JoviDeCroock mentioned this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants