From daa124a934ca18e87f24c2972ed0f0d1dc927caf Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Sun, 1 Dec 2024 12:47:06 -0600 Subject: [PATCH] fix: Ensure resolution of core types goes through typesVersions resolution (#4576) --- compat/client.d.ts | 4 +++- compat/src/index.d.ts | 4 +++- compat/src/suspense-list.d.ts | 4 +++- compat/src/suspense.d.ts | 4 +++- compat/test/ts/tsconfig.json | 7 +++++-- hooks/src/index.d.ts | 4 +++- jsx-runtime/src/index.d.ts | 6 ++++-- src/internal.d.ts | 4 +++- src/jsx.d.ts | 2 +- 9 files changed, 28 insertions(+), 11 deletions(-) diff --git a/compat/client.d.ts b/compat/client.d.ts index 5daf8ea1e5..cdf7ee241e 100644 --- a/compat/client.d.ts +++ b/compat/client.d.ts @@ -1,4 +1,6 @@ -import * as preact from '../src'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import * as preact from 'preact'; export function createRoot(container: preact.ContainerNode): { render(children: preact.ComponentChild): void; diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index d6b7aa3156..7ceaa09e30 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -1,5 +1,7 @@ import * as _hooks from '../../hooks'; -import * as preact from '../../src'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import * as preact from 'preact'; import { JSXInternal } from '../../src/jsx'; import * as _Suspense from './suspense'; import * as _SuspenseList from './suspense-list'; diff --git a/compat/src/suspense-list.d.ts b/compat/src/suspense-list.d.ts index caa1eb6bff..0a3be0adc9 100644 --- a/compat/src/suspense-list.d.ts +++ b/compat/src/suspense-list.d.ts @@ -1,4 +1,6 @@ -import { Component, ComponentChild, ComponentChildren } from '../../src'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import { Component, ComponentChild, ComponentChildren } from 'preact'; // // SuspenseList diff --git a/compat/src/suspense.d.ts b/compat/src/suspense.d.ts index 63f2d5400e..65c2a9372a 100644 --- a/compat/src/suspense.d.ts +++ b/compat/src/suspense.d.ts @@ -1,4 +1,6 @@ -import { Component, ComponentChild, ComponentChildren } from '../../src'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import { Component, ComponentChild, ComponentChildren } from 'preact'; // // Suspense/lazy diff --git a/compat/test/ts/tsconfig.json b/compat/test/ts/tsconfig.json index 75fc121a5d..82b3d5f09e 100644 --- a/compat/test/ts/tsconfig.json +++ b/compat/test/ts/tsconfig.json @@ -8,7 +8,10 @@ "forceConsistentCasingInFileNames": true, "jsx": "react", "noEmit": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "paths": { + "preact": ["../../../src/index.d.ts"] + } }, "include": ["./**/*.ts", "./**/*.tsx"] -} +} \ No newline at end of file diff --git a/hooks/src/index.d.ts b/hooks/src/index.d.ts index 7bb441edb2..d7f77dbb49 100644 --- a/hooks/src/index.d.ts +++ b/hooks/src/index.d.ts @@ -1,4 +1,6 @@ -import { ErrorInfo, PreactContext, Ref, RefObject } from '../..'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import { ErrorInfo, PreactContext, Ref, RefObject } from 'preact'; type Inputs = ReadonlyArray; diff --git a/jsx-runtime/src/index.d.ts b/jsx-runtime/src/index.d.ts index 03845a1a9d..46649e8bdf 100644 --- a/jsx-runtime/src/index.d.ts +++ b/jsx-runtime/src/index.d.ts @@ -1,11 +1,13 @@ -export { Fragment } from '../../'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +export { Fragment } from 'preact'; import { ComponentType, ComponentChild, ComponentChildren, VNode, Attributes -} from '../../'; +} from 'preact'; import { JSXInternal } from '../../src/jsx'; export function jsx( diff --git a/src/internal.d.ts b/src/internal.d.ts index 0abfd37ab2..7733b0f279 100644 --- a/src/internal.d.ts +++ b/src/internal.d.ts @@ -1,4 +1,6 @@ -import * as preact from './index'; +// Intentionally not using a relative path to take advantage of +// the TS version resolution mechanism +import * as preact from 'preact'; export enum HookType { useState = 1, diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 766d079bff..7ad1d2b4ce 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -9,7 +9,7 @@ import { FunctionComponent, PreactDOMAttributes, VNode -} from './index'; +} from 'preact'; type Defaultize = // Distribute over unions