Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-file jsx paragma got TS2322: Type 'Element' is not assignable to type 'VNode'. #23457

Closed
TotooriaHyperion opened this issue Apr 17, 2018 · 5 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@TotooriaHyperion
Copy link

TotooriaHyperion commented Apr 17, 2018

TypeScript Version: 2.9.0-dev.20180414

Search Terms:
TS2322: Type 'Element' is not assignable to type 'VNode'.
Property 'isRootInsert' is missing in type 'Element'.
Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

// index.vue.tsx
/** @jsx h */
import Vue, { CreateElement, VNode } from 'vue';

export default class VuePreview extends Vue {
  render(h: CreateElement): VNode {
    return <div>VuePreview</div>;
  }
}

can be reproduced at [email protected]

Expected behavior:
compiled without error
Actual behavior:
Per-file JSX factories @jsx
successfully compiled this file to index.vue.js ⬇️

import Vue from 'vue';
export default class VuePreview extends Vue {
    render(h) {
        return h("div", null, "VuePreview");
    }
}
//# sourceMappingURL=index.vue.js.map

but type check got the error
TS2322: Type 'Element' is not assignable to type 'VNode'.
Property 'isRootInsert' is missing in type 'Element'.

Playground Link:

Related Issues:

@TotooriaHyperion TotooriaHyperion changed the title Per-file jsx paragma got Type 'Element' is not assignable to type 'VNode'. Per-file jsx paragma got TS2322: Type 'Element' is not assignable to type 'VNode'. Apr 17, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 17, 2018

can not reproduce this locally. can you share a self-contained repro project:

c:\test\23457>type package.json
{
  "private": true,
  "dependencies": {
    "vue": "^2.5.16"
  }
}

c:\test\23457>type tsconfig.json
{
    "compilerOptions": {
        "target": "es5",
        "jsx": "react"
    }
}

c:\test\23457>type a.tsx
// index.vue.tsx
/** @jsx h */
import Vue, { CreateElement, VNode } from 'vue';

export default class VuePreview extends Vue {
    render(h: CreateElement): VNode {
        return <div>VuePreview</div>;
    }
}

c:\test\23457>tsc --v
Version 2.9.0-dev.20180414

c:\test\23457>tsc

c:\test\23457>echo %ERRORLEVEL%
0

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Apr 17, 2018
@TotooriaHyperion
Copy link
Author

TotooriaHyperion commented Apr 19, 2018

https://github.com/TotooriaHyperion/tsc-vue-jsx-bug

got different error

src/index.tsx(6,27): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

when using with react:
https://github.com/TotooriaHyperion/tsc-vue-jsx-bug/tree/with-react

index.react.tsx is fine
index.vue.tsx got src/index.vue.tsx(6,5): error TS2322: Type 'Element' is not assignable to type 'VNode'.

Obviously,
TS7026 is because vue have not provided jsx typings officially.
TS2332 is because jsx in vue file with @jsx paragma is treated as a react-jsx.

#13890

@mhegazy
Copy link
Contributor

mhegazy commented Apr 19, 2018

Issue #13260 tracks adding needed support in TS to support vue and jsx.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@joma74
Copy link

joma74 commented May 31, 2018

Me too, but should work on pure Javascript too/not only .tsx files

// storybook-starter/src/stories/index.stories.js
.add("with JSX", function() {
    return Vue.extend({
      components: { MyButton },
      render() {
        return <my-button>With JSX</my-button>
      },
    })
  })

gives essentially the same

Type '() => Element' is not assignable to type '(createElement: CreateElement, hack: RenderContext<Record<string, any>>) => VNode'.
          Type 'Element' is not assignable to type 'VNode'.
            Property 'isRootInsert' is missing in type 'Element'.

plus 2 times

Property 'my-button' does not exist on type 'JSX.IntrinsicElements'.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

4 participants