class GenericClass<T> {
payload: T;
}
var genericObject = new GenericClass<{greeting: string}>();
function genericFunction<T>(object: GenericClass<T>, callback: (payload: T) => void) {
callback(object.payload);
}
// Works
genericFunction(genericObject, (payload) => {
// Here TS understands that payload have a property greeting
// and that payload.greeting is a string.
});
// Fails to compile with "Type 'T' has no property 'greeting' and no index signature.".
// Type of greeting is any
genericFunction(genericObject, ({greeting}) => {
});