interface MyInterface { CAT : { CAT : string ; } ; KITTY : { KITTY : string ; } ; } ; // interface MyInterface function Call ( t : T , k : K ) { console . log ( t ) ; // -> CAT console . log ( k ) ; // -> { CAT: '123' } if ( t == "CAT" ) { console . log ( k . CAT ) ; // Property 'CAT' does not exist on type '{ CAT: string; } | { KITTY: string; }'. // Property 'CAT' does not exist on type '{ KITTY: string; }' // Аналогичная ошибка и с k?.CAT и k["CAT"] } } Call ( "CAT" , { CAT : "123" } ) ;
if ( t == "CAT" ) { let some = k as MyInterface [ "CAT" ] ; console . log ( some . CAT ) ; // success }