2016-09-19 35 views
0

我有兩個數據集,每個數據集都是不同的泛型類型。一切正常,除了在初始化其中用於Typeahead/TypeScript - 多個不同類型的數據集

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'.

作爲一種變通方法我投的數據集但什麼是正確的解決方案?

回答

1

As a workaround I cast Datasets as , but what would be the correct solution

任何合併兩種類型的例如a map或只是:

type NodeOrBudget = Node | Budget; 

var localDataset: Twitter.Typeahead.Dataset<NodeOrBudget>; 
var globalDataset: Twitter.Typeahead.Dataset<NodeOrBudget>; 
... 
typeahead(options, localDataset, globalDataset);