Can someone help me with a Typescript question I have?
// Looking for the best way to handle Params and Options in this scenario
interface Params {
name: string;
age: number;
}
interface Option {
callback: (params: Params | Params[]) => void
}
// My code snippet
const optionError: Option = {
// Need params type as Params only
callback: (params: Params) => {
console.log(params.name)
console.log(params.age)
}
}
const optionOK: Option = {
callback: (params) => {
const p = params as Params; // Is there an alternative to redefining the same parameter?
console.log(p.name)
console.log(p.age)
}
}
Is there a different approach than defining the same parameter again?