Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

ts 中高阶函数的类型问题

createComponent 的定义

image.png

使用在这里

image.png

image.png

问题如下

按照现在的写法,这里的高阶函数 createComponent 没有接受到外部传入的泛型,将使用默认的泛型DefaultProps等,这里如何使得<Props = DefaultProps...>等类型信息可以从外部传入?

比如:

传入 Props: { name: string },让createComponent接收到的 Props 类型就是我这里传入的。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

那三个泛型是你在用createComponent返回的函数时用的

const component = createComponent('xxx');
component<SomeProps,SomeEvents,SomeSlots>(...)

而且你这也不叫高阶函数


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...