当你定义的组件props 类型需要一个泛型时,例如
<script lang="ts">
export let dataSource:DataSource<T>;
</script>
T 会提示Cannot find name 'T'
官方文档中提到的不多,有这样一段:
A few features are missing from taking full advantage of TypeScript in more advanced use cases like typing that a component implements a certain interface, explicitly typing slots, or using generics. These things are possible using experimental advanced type capabilities. See this RFC for more information on how to make use of them.
所以我们可以在script 标签上采用generics 添加泛型定义
修改为
<script lang="ts" generics="T extends any">
export let dataSource:DataSource<T>;
</script>