这是方法
// Returns fitting styles for dragged/idle items
const fn = (
order: any,
down?: boolean,
originalIndex?: number,
curIndex?: number,
y: number = 0
) => (index: number) =>
down && index === originalIndex
? {
y: curIndex && curIndex * 100 + y,
scale: 1.1,
zIndex: '1',
shadow: 15,
immediate: (n: string):boolean => {
return n === 'y' || n === 'zIndex'
}
}
: {
y: order.indexOf(index) * 100,
scale: 1,
zIndex: '0',
shadow: 1,
immediate: false
}
这是方法的调用
const order = useRef(list.map((_, index) => index)) // Store indicies as a local ref, this represents the item order
const [springs, setSprings] = useSprings(list.length, fn(order.current)) //这里会报错
然后ts错类型不兼容 我就真心不知道 这为什么不兼容了
实在是无法理解 我总感觉我ts出问题了
我今天也是恰好遇到个类似的,我那个是判断不严密的问题。感觉你immediate函数内的判断有问题。我猜现有的判断逻辑是不是会返回除了boolean类型以外的值? 与你定义的函数返回值类型不同,所以报错。你这里:
可以尝试换成
或者