Open1
プロを目指す人のためのTypeScript入門 メモ
3.3部分型関係
以下のような場合、Human
型はAnimal
型の部分型となるので、helloFunction
の引数にhuman
が入っても問題ない。
type Animal = {
age: number
}
type Human = {
age: number
name: string
}
const human: Human = {
age: 25,
name: "yuma"
}
const helloFunction = (data:Animal) => {
console.log("data", data)
}
helloFunction(human)