You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Flow type information across *ngFor-like directives #10510
class Person {
first: string;
last:string;
}
class MyComp {
items: string[];
people: Person[];
}
/**
* Assume we have template such as this:
* <div *ngFor="let person of people; trackBy: foo">
* {{people.length}}{{item.first}}
* </div>
*/
// These global variables are here only to flow the type information.
var _comp: MyComp;
var _peopleLetType = NgFor.extractTypeFromOf(_comp && _comp.people);
class MyComponentFactory{
context: MyComp;
ngFor: NgFor<typeof _peopleLetType> = new NgFor<typeof _peopleLetType>(new DivInnerFactory());
create() {
this.ngFor.of = this.context.people;
}
}
class DivInnerFactory {
context: NgForRow<typeof _peopleLetType>;
text: string;
create() {
this.context.$implicit.first; // expected type OK because $implicit is Person
this.context.$implicit.name; // expected type error because $implicit is Person
}
}
class NgForRow<T> {
$implicit: T;
}
@Component({
// we need some way to hint to the template generated which property to use for type extraction
// and which static function to use with that property.
typeTransformation: ['of', NgFor.extractTypeFromOf]
})
class NgFor<T>{
@Input({typeTransform: NgFor.extractTypeFromOf})
of: T[];
constructor(factory: Factory) {}
static extractTypeFromOf<T>(expr: T[]|Iterable<T>): T {return undefined;}
}
interface Factory {
create();
}
interface Iterable<T> {}
function Component(a:any): Function { return null; }
function Input(a:any): Function { return null; }
Activity
chuckjaz commentedon Oct 19, 2016
Closed in favor of #12398
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.