-
Couldn't load subscription status.
- Fork 819
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
4.12.0
Current Behavior
It appears that the TypeScript definitions for JSX support in Stencil are not completely correct, and are causing issue when used with third-party tools (like @typescript-eslint)
Expected Behavior
JSX.Element type is resolved correctly
System Info
System: node 20.11.0
Platform: darwin (23.2.0)
CPU Model: Apple M1 Pro (10 cpus)
Compiler: /Users/mak13180/site/esri/arcgis-web-components/node_modules/@stencil/core/compiler/stencil.js
Build: 1705333241
Stencil: 4.10.0 🍪
TypeScript: 5.3.3
Rollup: 2.42.3
Parse5: 7.1.2
jQuery: 4.0.0-pre
Terser: 5.26.0Steps to Reproduce
I made a small reproduction case based on the JSX typings in Stencil: source
See the error on line 16
Further, see that see that typescript compiler resolves the type as "error":
out.mp4
This is because TypeScript is hardcoded to look for Element type/interface in the JSX namespace
In the above demo, uncomment line 8 (not present in Stencil's typings), and see how the typescript compiler now correctly resolves the JSX type, and also the typescript-eslint error is resolved
Code Reproduction URL
- Initial problem: ESLint Playground - Example 1: "Unsafe return of an
anytyped value." - After setting
type Element = VNodein JSX namespace: ESLint Playground - Example 2: "'Fragment' cannot be used as a JSX component.
Its return type 'VNode | VNode[]' is not a valid JSX element." - Stencil Component Starter Reproduction
Additional Information
For reference, here are examples of Elements interface/type being included in the JSX element in other popular libraries:
- React - https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6d0e970598392a8c1c62019150e4f197fadf301c/types/react/jsx-runtime.d.ts#L5
- PReact - https://github.com/preactjs/preact/blob/49433b3a16a629db3a9a39df3f9f81ff703078bb/src/jsx.d.ts#L41
- dom-expressions (used by SolidJS and others) - https://github.com/ryansolid/dom-expressions/blob/eb9a6bcf640b04c1d1c889d9983914a2776093fe/packages/dom-expressions/src/jsx.d.ts#L12
- Qwik - https://github.com/BuilderIO/qwik/blob/408576e8a2e1d11fabf030f37b5941c0a3274669/packages/qwik/src/core/render/jsx/types/jsx-qwik.ts#L7
After debugging typescript-eslint and reading TypeScript source code, it appears that TypeScript is hardcoded to look for JSX.Element type/interface, rather than look at the return type of the jsxFactory:
function getJsxElementTypeAt(location: Node): Type {
return getJsxType(JsxNames.Element, location);
}