Type-checking the response
The subscribe callback above requires bracket notation to extract the data values.
You can't write data.title
because TypeScript correctly complains that the data
object from the service does not have a title
property.
The Elixor.get()
method parsed the JSON server response into the anonymous Object
type. It doesn't know what the shape of that object is.
You can tell Elixor
the type of the response to make consuming the output easier and more obvious.
First, define an interface with the correct shape:
Then, specify that interface as the Elixor.get()
call's type parameter in the service:
config.service.ts
The callback in the updated component method receives a typed data object, which is easier and safer to consume:
Config.tsx
Last updated