如何使用 flowtype 以外的 React$Element 类型键入 JSX?
How to type JSX with other types than React$Element with flowtype?
我将 flowtype 与 Vue.js 一起使用,并为 Vue.js 添加了类型声明。
然后,我还将 JSX 语法与 babel-plugin-transform-vue-jsx 一起使用。
虽然我想输入 JSX 标签作为 VNode,flowtype 引擎将 JSX 标签检测为 React$Element,所以它不起作用。
有没有人知道如何让 flowtype 引擎将 JSX 检测为另一种类型,或者知道解决这个问题的其他好方法?
我需要你的帮助。
谢谢。
完整代码在这里。
https://github.com/kentrino/vue-js-webpack-flowtype-example
import style from './Test.css';
const test: ComponentOptions = {
render (h): VNode {
return <div><h1 class={style.red}>Yeah!! This is test.</h1></div>
// ^^^^^ React$Element. This type is incompatible with
// 5: render (h: any): VNode {
// ^^^^^ VNode
},
name: 'Test'
}
你可以让 Flow 使用 React 以外的东西来检查你的 JSX 类型。只需在文件顶部放置一个 @jsx
标签(我将我的标签放在 flow 标签的正下方)
// @flow
// @jsx somethingBesidesReact.createElement
在你的例子中,你正在使用 Vue 和 babel-plugin-transform-vue-jsx
插件来转换你的 JSX,它简单地转换为 h
https://github.com/vuejs/babel-plugin-transform-vue-jsx
所以,在你的情况下,这应该有效
// @flow
// @jsx h
import style from './Test.css';
const test: ComponentOptions = {
render (h: any): VNode {
return <div><h1 class={style.red}>Yeah!! This is test.</h1></div>
},
name: 'Test'
}
export default test;
我将 flowtype 与 Vue.js 一起使用,并为 Vue.js 添加了类型声明。 然后,我还将 JSX 语法与 babel-plugin-transform-vue-jsx 一起使用。
虽然我想输入 JSX 标签作为 VNode,flowtype 引擎将 JSX 标签检测为 React$Element,所以它不起作用。
有没有人知道如何让 flowtype 引擎将 JSX 检测为另一种类型,或者知道解决这个问题的其他好方法?
我需要你的帮助。
谢谢。
完整代码在这里。 https://github.com/kentrino/vue-js-webpack-flowtype-example
import style from './Test.css';
const test: ComponentOptions = {
render (h): VNode {
return <div><h1 class={style.red}>Yeah!! This is test.</h1></div>
// ^^^^^ React$Element. This type is incompatible with
// 5: render (h: any): VNode {
// ^^^^^ VNode
},
name: 'Test'
}
你可以让 Flow 使用 React 以外的东西来检查你的 JSX 类型。只需在文件顶部放置一个 @jsx
标签(我将我的标签放在 flow 标签的正下方)
// @flow
// @jsx somethingBesidesReact.createElement
在你的例子中,你正在使用 Vue 和 babel-plugin-transform-vue-jsx
插件来转换你的 JSX,它简单地转换为 h
https://github.com/vuejs/babel-plugin-transform-vue-jsx
所以,在你的情况下,这应该有效
// @flow
// @jsx h
import style from './Test.css';
const test: ComponentOptions = {
render (h: any): VNode {
return <div><h1 class={style.red}>Yeah!! This is test.</h1></div>
},
name: 'Test'
}
export default test;