[pnpm] The inferred type of 'xxx' cannot be named without a reference to '.pnpm/xxx'
related to https://github.com/microsoft/typescript-go/issues/1034 (using 7.0.0-dev.20251204.1)
Steps to reproduce
https://github.com/aramissennyeydd/typescript-go-pnpm-error
Write a function whose return value is a type from a package installed with PNPM. In the example above that's @testing-library/react.
Behavior with [email protected]
No errors.
Behavior with tsgo
> [email protected] tsgo /Users/aramis.sennyey/Projects/tsgo-errors/packages/test
> tsgo
test-utils.tsx:4:7 - error TS2742: The inferred type of 'customRender' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@testing-library/dom/types/queries'. This is likely not portable. A type annotation is necessary.
4 const customRender = (
~~~~~~~~~~~~
Found 1 error in test-utils.tsx:4
+1 we are seeing quite a few of these errors as well
this is related to #2234 . in fact if you change:
to
const customRender: (
ui: React.ReactElement<any>,
options?: RenderOptions & { customLayerManager?: React.FC<any> }
) => RenderResult = (
ui,
options
) =>
render(ui, {
wrapper: () => <></>,
...options,
}) as RenderResult
or
function customRender (
ui: React.ReactElement<any>,
options?: RenderOptions & { customLayerManager?: React.FC<any> }
): RenderResult {
return render(ui, {
wrapper: () => <></>,
...options,
}) as RenderResult
}
the error disappears.
the inferred, broken type for that function is
const customRender: (ui: React.ReactElement<any, string | React.JSXElementConstructor<any>>, options?: (RenderOptions<typeof import("/some/path/to/node_modules/.pnpm/@[email protected]/node_modules/@testing-library/dom/types/queries"), HTMLElement, HTMLElement> & { ...; }) | undefined) => RenderResult
instead of the expected:
import { RenderResult, RenderOptions } from '@testing-library/react';
declare const customRender: (ui: React.ReactElement<any>, options?: RenderOptions & {
customLayerManager?: React.FC<any>;
}) => RenderResult;
#1034 solved some of my issues, but like the main post, I still have one specific dependency that has the same error.