Reputation: 1271
I want to use a type (or interface) like this:
type FoodTable = {
foodId: string;
foodName: string;
};
And a function that accepts the type as a generic argument:
function promisifyData<T>(data): SomePromiseyData<T> {
// code here
}
so if I invoke the function using FoodTable
as the generic:
promisifyData<FoodTable>(someParam);
// returns:
{
foodId: Promise {}, // resolves to string
foodName: 'some name'
}
Basically I want to know how to define the SomePromiseyData
type.
Here is a link to the typing I'm trying to achieve: typescriptlang.org/play
Upvotes: 0
Views: 27
Reputation: 174309
Your data
parameter has no type. It should be of type T
:
function makePromiseyData<T>(data: T) { /*...*/ }
See fixed version.
Upvotes: 4
Reputation: 887453
You need to declare your data
parameter as having a type: data: T
.
Upvotes: 1