Typeahead/TypeScript - 不同通用类型的多个数据集
Typeahead/TypeScript - multiple Datasets of different generic type
我有两个数据集,每个都有不同的通用类型。一切正常,除了
的初始化
var localDataset: Twitter.Typeahead.Dataset<Node>;
var globalDataset: Twitter.Typeahead.Dataset<Budget>;
...
typeahead(options, localDataset, globalDataset);
我收到错误
Error:(130, 13) TS2453: The type argument for type parameter 'T'
cannot be inferred from the usage. Consider specifying the type
arguments explicitly. Type argument candidate 'Node' is not a valid
type argument because it is not a supertype of candidate 'Budget'.
作为解决方法,我将数据集转换为 ,但正确的解决方案是什么?
As a workaround I cast Datasets as , but what would be the correct solution
任何合并这两种类型的东西,例如一个 map
或只是:
type NodeOrBudget = Node | Budget;
var localDataset: Twitter.Typeahead.Dataset<NodeOrBudget>;
var globalDataset: Twitter.Typeahead.Dataset<NodeOrBudget>;
...
typeahead(options, localDataset, globalDataset);
我有两个数据集,每个都有不同的通用类型。一切正常,除了
的初始化var localDataset: Twitter.Typeahead.Dataset<Node>;
var globalDataset: Twitter.Typeahead.Dataset<Budget>;
...
typeahead(options, localDataset, globalDataset);
我收到错误
Error:(130, 13) TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Node' is not a valid type argument because it is not a supertype of candidate 'Budget'.
作为解决方法,我将数据集转换为 ,但正确的解决方案是什么?
As a workaround I cast Datasets as , but what would be the correct solution
任何合并这两种类型的东西,例如一个 map
或只是:
type NodeOrBudget = Node | Budget;
var localDataset: Twitter.Typeahead.Dataset<NodeOrBudget>;
var globalDataset: Twitter.Typeahead.Dataset<NodeOrBudget>;
...
typeahead(options, localDataset, globalDataset);