나는 컨텍스트 공급자는 사용자 데이터 스트림 응용 프로그램 전반에 걸쳐.
나는 학생이 인터페이스::
export interface Student extends User
고 싶은 공급자가 반환하는 사용자 데이터의 유형 Student
나 User
다음과 같다:
let userData: Student | User = null;
에 액세스하려고 시도하는 경우 제공할 수 있는 학생들, userData?.currentTeam
대 코드를 발생 다음과 같은 오류가:
Property 'currentTeam' does not exist on type 'Student | User'.
Property 'currentTeam' does not exist on type 'User'.ts(2339)
내가 찾는 데 도움이 필요한 이유 그것은 기본값으로 사용하는 부모 인터페이스와 방법을 허용하는 옵션입니다.
'currentTeam' in userData ? userData.currentTeam.teamName: 'No Team Set'