I have added a interface, so why I have to set a type on my function for each parameter ? (id, name, year)
interface trackType {
id: string,
name: string,
year: number
}
const tracks: Array<string> = [];
function addTrack<trackType>(id, name, year) {
}
CodePudding user response:
In this case you should pass to addTrack
the whole object.
Consider this example:
interface TrackType {
id: string,
name: string,
year: number
}
const tracks: Array<string> = [];
function addTrack({ id, name, year }: TrackType) {
}
addTrack({ id: 'a', name: 'John', year: 100 })