Reputation: 20007
What is the proper way to type this object?
{a: 1, b: n => n + 1}
Here's my attempt.
let foo: {a: number, b: number => number} = {a: 1, b: n => n + 1}
However, this isn't the correct syntax.
Upvotes: 0
Views: 88
Reputation: 95764
Function type expressions need parentheses and parameter names. From the handbook:
Note that the parameter name is required. The function type
(string) => void
means “a function with a parameter named string of type any“!
let foo: {a: number, b: (n: number) => number} = {a: 1, b: n => n + 1}
Upvotes: 3
Reputation: 11474
let foo: {a: number, b: (n: number) => number} = {a: 1, b: n => n + 1}
Upvotes: 3