[bug] JSX support in `preserve` mode w/ custom `jsxImportSource` causing `TS2875`
I have a tsconfig.json approximately like:
"compilerOptions": {
"module": "es2022",
"jsx": "preserve",
"jsxImportSource": "external/solid",
"baseUrl": ".",
"paths": {
"external/*": ["./external/*"]
},
"target": "es2022",
error TS2875: This JSX tag requires the module path 'external/solid/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
even though this file exists:
❯ cat external/solid/jsx-runtime.d.ts
export * from "./solid/jsx";
❯ ls -l external/solid/solid/jsx.d.ts
-rw-r--r-- 1 tmm1 staff 73590 Apr 4 17:34 external/solid/solid/jsx.d.ts
Is this due to compilerOptions.paths?
baseUrl is not supported: #474
Thanks. I removed baseUrl, and also tried to add paths['*'] = ['*'], but the behavior remains the same.
Ah, well I don't think jsxImportSource has been implemented yet.
The error comes from:
https://github.com/microsoft/typescript-go/blob/34dd1030316c6f25c5af8fdf2bef671fa0413a8d/internal/checker/jsx.go#L1249-L1259
where getJSXImplicitImportBase does plumb the value of jsximportsource through. So the issue is likely in resolveExternalModule here?
https://github.com/microsoft/typescript-go/blob/34dd1030316c6f25c5af8fdf2bef671fa0413a8d/internal/checker/checker.go#L14208-L14209
// !!! The following only implements simple module resolution
sourceFile := c.program.GetResolvedModule(ast.GetSourceFileOfNode(location), moduleReference)
There are some references to "the synthesized JSX runtime import" which I think may be missing on the Corsa side.
Atleast when I look at the program's resolvedModules, there is no entry for jsx-runtime which causes the failure.
Imports synthesized here:
https://github.com/microsoft/TypeScript/blob/0693cc72e6ddb6c7468a14e05888efa2f43ac7b0/src/compiler/program.ts#L3512-L3516
const jsxImport = getJSXRuntimeImport(getJSXImplicitImportBase(options, file), options);
if (jsxImport) {
// synthesize `import "base/jsx-runtime"` declaration
(imports ||= []).push(createSyntheticImport(jsxImport, file));
}
and unimplemented here:
https://github.com/microsoft/typescript-go/blob/ce957e2f150a08e1de55caa4b7938db160b1e497/internal/parser/references.go#L11-L12
A little stuck because collectExternalModuleReferences is in internal/parser but the original version needs access to compiler options.
Also createSyntheticImport needs to be ported which is probably best done by someone familiar with the parser internals. A *ast.NodeFactory reference will be required for that function.
cc @ahejlsberg
Stuck a draft on #780 if you could test that to see if it works.
Works as advertised!