Here is the code I have written:
interface ImyInterface {
v: number;
}
class A implements OnInit {
ngOnInit() {
let myObservable$ = getObs();
myObservable$.subscribe(data => {
const foo = data as ImyInterface;
foo. // <-- VS Code IDE autcompletes with 'v'
});
}
};
Despite this, I wanted to minimize extra variable declaration and attempted the following:
myObservable$.subscribe(data => {
data = data as ImyInterface;
data. // <-- VS Code IDE didn't autocomplete
});
Why did this alternative approach not work? Could it possibly be related to variable scope or shadowing? My understanding is limited since I am still a beginner.