Closed chenyulun closed 2 months ago
再者,packages/varlet-ui/src/card/Card.vue
里面的<string>toSizeUnit(width)
可能修改为toSizeUnit(width) as string
eslint的修改参考如下:
module.exports = {
// 其他代码
overrides: [
{
files: ['*.vue'],
parserOptions: {
// Note: only `null` can override the previous config. `undefined` would be ignored.
project: null,
// Use `espree` for js/jsx script blocks to get better performance.
// Note this format can only be used when there's no `project` set.
parser: {
js: 'espree',
jsx: 'espree',
ts: require.resolve('@typescript-eslint/parser'),
tsx: require.resolve('@typescript-eslint/parser')
// Leave the template parser unspecified, so that it could be determined by `<script lang="...">`.
},
extraFileExtensions: ['.vue'],
ecmaFeatures: {
jsx: true
}
},
rules: {
// Allow `<script lang="ts">` & `<script lang="tsx">`, but not other langs.
'vue/block-lang': [
'error', {
script: {
lang: ['ts', 'tsx'],
allowNoLang: true
}
}
],
// Don't apply those rules that need type information for `.vue` files.
// Because it's not supported for `script lang="tsx"` in `.vue` files yet.
// https://github.com/vuejs/create-vue/issues/123#issuecomment-1189934982
// That includes (as of v22):
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-for-in-array': 'off',
'@typescript-eslint/no-implied-eval': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/prefer-includes': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-readonly': 'off',
'@typescript-eslint/prefer-reduce-type-parameter': 'off',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/require-array-sort-compare': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off'
}
}
],
}
或者参考使用@antfu/eslint-config
,升级eslint到9
不需要支持 lang="tsx"
,需要接受 vnode
的情况,可以参考 varlet 组件源码中的
export const MaybeVNode = defineComponent({
props: {
is: {
type: [String, Object] as PropType<string | VNode>,
},
tag: {
type: String,
default: 'span',
},
},
setup(props) {
return () => (isString(props.is) ? h(props.tag, props.is) : props.is)
},
})
处理 vnode 更加平滑,并且能最大程度的保留模板编译优势。
Feature request 🚀
Expected:
部分组件可能能接受Vnode自定义渲染内容,不想额外写
.tsx
单独写函数,希望能支持vue文件里面支持tsx
Examples:
需要完成的修改包括:
lang
值,然后传给compileScript
让他先用babel处理后再用esbuild
处理lang="tsx"
,eslint也要修复本地项目案例代码:
compileScript.ts文件的修改
Others:
如果可以的话,我可以提PR