個人用備忘録です
typeof
function toUpperCase(x: string | number) {
if (typeof x === 'string') {
return x.toUpperCase();
}
return '';
}
in
type Enginner = {
name:string;
role: string;
}
type Blogger = {
name:string;
follower: string;
}
type EngineerBlogger = Engineer & Blogger;
function describeProfile(nomadWorker: EngineerBlogger) {
console.log(nomadWorker.name);
if ('role' in nomadWorker) {
console.log(nomadWorker.role);
}
if ('follower' in nomadWorker) {
console.log(nomadWorker.follower);
}
}
instanceof
Class Dog {
speak() {
console.log('bwbw')
}
}
Class Bird {
speak() {
console.log('fuwagifu')
}
fly() {
console.log('fly')
}
}
function havePet() {
pet.speak();
if (pet instanceof Bird) {
pet.fly();
}
}
havePet(new Bird());