¿Qué es el "tipo '{}'"?
En TypeScript, qué es exactamentetype '{}'
¿Y cómo se relaciona con otros tipos incorporados?
Por ejemplo, la última línea del siguiente ejemplo daType '{}' is not assignable to type 'number'
, y no tengo completamente claro quétype {}
es en este contexto, o de hecho cómo se produce:
// A function taking no arguments and returning T
type NoArgsFn<T> = () => T;
// An instance of NoArgsFn<number>
function get_the_answer(): number {
return 42;
}
// Call the supplied function and return its value
function call<T, Fn extends NoArgsFn<T>>(fn: Fn): T {
return fn();
}
// Expect this to be equivalent to `let the_answer: number = 42', but
// instead get "Type '{}' is not assignable to type 'number'"
let the_answer: number = call(get_the_answer);