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
fix(types): fix the types of the entries and plugins #951
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add tests to make sure this change works as expected?
f520488
to
2fb8054
Compare
你是在什么情况下需要给这几个指定文件定义类型? |
@zengyue 小程序里,因为小程序开发模式下有 2M 限制,只好引入 min 版本,而目前 min 版本没有类型定义: |
@zengyue 另外,老哥,你使用的 vscode 吗?是的话可以安装个 prettier 插件,然后开启仅项目存在 .prettierrc 之类的配置文件才生效的选项,这样咱们的风格能统一一点,或者需要我在 pre-commit 时加上 prettier 嘛。 |
这个比较难统一,因为每个人用的ide可能都不太一样 |
这个是单包2m, 还是所有总和2M ? |
另外,你是直接用的F2, 没有用wx-f2 和 my-f2 ? |
微信小程序总的项目体积 2M 以内才能预览,使用 Taro 的话如果在开发时开启压缩,又太慢了,当然也可以通过 alias 指向 min 版本,不过给 min 版本加上类型直接引用也没啥不妥。 |
你们要是提供个 taro-f2 我可能还能直接使用 😂 |
我本地搞的 Taro-f2。。可以参考: import _ from './Chart.less'
import F2 from '@antv/f2/dist/f2.min.js'
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
import { Canvas } from '@tarojs/components'
import { CanvasProps } from '@tarojs/components/types/Canvas'
import { createSelectorQuery, getSystemInfoSync } from '@tarojs/taro'
import { wait } from 'vtils'
export interface ChartProps<TRecord extends F2.DataRecord> extends CanvasProps {
config: (chart: F2.Chart<TRecord>) => any
}
let counter = 1
export function Chart<TRecord extends F2.DataRecord>(
props: ChartProps<TRecord>,
) {
const id = useMemo(() => `chart_${counter++}`, [])
const canvasElRef = useRef<any>()
useEffect(() => {
wait(0).then(() => {
createSelectorQuery()
.select(`#${id}`)
.fields({
node: true,
size: true,
})
.exec(res => {
const { node, width, height } = res[0]
const context = node.getContext('2d')
const pixelRatio = getSystemInfoSync().pixelRatio
// 高清设置
node.width = width * pixelRatio
node.height = height * pixelRatio
const chart = new F2.Chart<TRecord>({
context,
width,
height,
pixelRatio,
})
props.config(chart)
chart.render()
canvasElRef.current = chart.get('el')
})
})
}, [])
const handleTouchStart = useCallback((e: any) => {
canvasElRef.current?.dispatchEvent('touchstart', e)
}, [])
const handleTouchMove = useCallback((e: any) => {
canvasElRef.current?.dispatchEvent('touchmove', e)
}, [])
const handleTouchEnd = useCallback((e: any) => {
canvasElRef.current?.dispatchEvent('touchend', e)
}, [])
return (
<Canvas
{...props}
type='2d'
id={id}
className={`${_.chart} ${props.className || ''}`}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
/>
)
} |
没,只是确认下 😃 |
|
这个可以的 |
ok, 那我晚点提个 pr |
Checklist
Description of change
declare module '***.js' {}
是无法给指定文件定义类型的,因此,创建了一个patch-types.js
的脚本直接生成入口文件的类型定义文件;实际效果: