반응형
SMALL
| => javascript의 || 느낌 (or)
& => javascript의 && 느낌 (and)
interface Person {
name: string;
}
interface Liftspan {
birth: Date;
death?: Date;
}
type PersonSpan = Person & Liftspan
const spans:PersonSpan = {
name: 'kiwon',
// birth: new Date('2022-06-09'),
death: new Date('2122-06-09')
}
/**
Type '{ name: string; death: Date; }' is not assignable to type 'PersonSpan'.
Property 'birth' is missing in type '{ name: string; death: Date; }' but required in type 'Liftspan'.(2322)
input.tsx(6, 5): 'birth' is declared here.
*/
type PersonSpan = Person | Liftspan
const spans:PersonSpan = {
name: 'kiwon',
// birth: new Date('2022-06-09'),
death: new Date('2122-06-09')
}
/*
정상 작동
*/
반응형
LIST
'TypeScript' 카테고리의 다른 글
타입단언보다 타입선언을 사용하자(feat. DOM element는 좀 다름) (0) | 2023.02.25 |
---|---|
keyof 사용법 (0) | 2023.02.25 |
타입을 집합으로 이해하기 (0) | 2022.06.19 |
코드생성과 타입은 관계가 없음 (0) | 2022.06.19 |
noImplicitAny, strictNullChecks의 선언 (0) | 2022.06.19 |