-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): resolve types via package.json for directory import (#22878)
Does a package resolve when resolving types for a directory (copying the behaviour that typescript does).
1 parent
a3fc3a1
commit d27831d
Showing
9 changed files
with
226 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"base": "npm", | ||
"args": "check --all main.ts", | ||
"output": "main.out" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Download http://localhost:4545/npm/registry/@denotest/types-pkg-json-import | ||
Download http://localhost:4545/npm/registry/@denotest/types-pkg-json-import/1.0.0.tgz | ||
Check file:///[WILDLINE]/main.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createContext } from "npm:@denotest/types-pkg-json-import"; | ||
import { useContext } from "npm:@denotest/types-pkg-json-import/hooks"; | ||
|
||
export interface Foo { | ||
foo: string; | ||
} | ||
|
||
export const CTX = createContext<Foo | undefined>(undefined); | ||
|
||
function unwrap(foo: Foo) {} | ||
|
||
export function useCSP() { | ||
const foo = useContext(CTX); | ||
// previously this was erroring | ||
if (foo) { | ||
unwrap(foo); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/testdata/npm/registry/@denotest/types-pkg-json-import/1.0.0/hooks/src/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// this directory import was not working (it should resolve via the package.json) | ||
import { PreactContext } from '../..'; | ||
|
||
export declare function useContext<T>(context: PreactContext<T>): T; |
14 changes: 14 additions & 0 deletions
14
tests/testdata/npm/registry/@denotest/types-pkg-json-import/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@denotest/types-directory-import", | ||
"version": "1.0.0", | ||
"exports": { | ||
".": { | ||
"types": "./src/index.d.ts", | ||
"import": "./dist/preact.mjs" | ||
}, | ||
"./hooks": { | ||
"types": "./hooks/src/index.d.ts", | ||
"import": "./hooks/dist/hooks.mjs" | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/testdata/npm/registry/@denotest/types-pkg-json-import/1.0.0/src/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
export as namespace preact; | ||
|
||
export interface VNode<P = {}> { | ||
type: any | string; | ||
props: P & { children: ComponentChildren }; | ||
key: Key; | ||
/** | ||
* ref is not guaranteed by React.ReactElement, for compatibility reasons | ||
* with popular react libs we define it as optional too | ||
*/ | ||
ref?: Ref<any> | null; | ||
/** | ||
* The time this `vnode` started rendering. Will only be set when | ||
* the devtools are attached. | ||
* Default value: `0` | ||
*/ | ||
startTime?: number; | ||
/** | ||
* The time that the rendering of this `vnode` was completed. Will only be | ||
* set when the devtools are attached. | ||
* Default value: `-1` | ||
*/ | ||
endTime?: number; | ||
} | ||
|
||
export type Key = string | number | any; | ||
|
||
export type RefObject<T> = { current: T | null }; | ||
export type RefCallback<T> = (instance: T | null) => void; | ||
export type Ref<T> = RefObject<T> | RefCallback<T> | null; | ||
|
||
export type ComponentChild = | ||
| VNode<any> | ||
| object | ||
| string | ||
| number | ||
| bigint | ||
| boolean | ||
| null | ||
| undefined; | ||
export type ComponentChildren = ComponentChild[] | ComponentChild; | ||
|
||
export interface FunctionComponent<P = {}> { | ||
(props: any, context?: any): VNode<any> | null; | ||
displayName?: string; | ||
defaultProps?: Partial<P> | undefined; | ||
} | ||
export interface FunctionalComponent<P = {}> extends FunctionComponent<P> {} | ||
|
||
// | ||
// Context | ||
// ----------------------------------- | ||
export interface Consumer<T> | ||
extends FunctionComponent<{ | ||
children: (value: T) => ComponentChildren; | ||
}> {} | ||
export interface PreactConsumer<T> extends Consumer<T> {} | ||
|
||
export interface Provider<T> | ||
extends FunctionComponent<{ | ||
value: T; | ||
children?: ComponentChildren; | ||
}> {} | ||
export interface PreactProvider<T> extends Provider<T> {} | ||
export type ContextType<C extends Context<any>> = C extends Context<infer T> | ||
? T | ||
: never; | ||
|
||
export interface Context<T> { | ||
Consumer: Consumer<T>; | ||
Provider: Provider<T>; | ||
displayName?: string; | ||
} | ||
export interface PreactContext<T> extends Context<T> {} | ||
|
||
export function createContext<T>(defaultValue: T): Context<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters