interface IPerson {
name: string;
age: number;
speak(): string;
}
type PersonType = {
name: string;
age: number;
speak(): string;
};
let personInterface: IPerson = {} as any;
let personType: PersonType = {} as any;
personInterface = personType;
personType = personInterface;
type PersonID = string & { readonly brand: unique symbol };
function PersonID(id: string): PersonID {
return id as PersonID;
}
function getPersonById(id: PersonID) {}
getPersonById(PersonID('id-aaaaaa'));
getPersonById('id-aaaaaa');
// error TS 2345: Argument of type 'string' is not assignable to parameter of type 'PersonID'.
// Type 'string' is not assignable to type '{ readonly brand: unique symbol; }'.
만약 어떤 새가 오리처럼 걷고, 헤엄치고, 꽥꽥거리는 소리를 낸다면 나는 그 새를 오리라고 부를 것이다.
TypeScript 는 duck typing 아님
class Duck:
def sound(self):
print u "꽥꽥"
class Dog:
def sound(self):
print u "멍멍"
def get_soung(animal):
animal.sound()
def main():
bird = Duck()
dog = Dog()
getSound(bird)
getSound(dog)