Skip to content

Instantly share code, notes, and snippets.

@alxhub
Last active July 20, 2018 18:44
Show Gist options
  • Save alxhub/deb2d595a607d42a0423a01c127408ed to your computer and use it in GitHub Desktop.
Save alxhub/deb2d595a607d42a0423a01c127408ed to your computer and use it in GitHub Desktop.
declare class NgForOfContext<T> {
$implicit: T;
ngForOf: Array<T>;
index: number;
count: number;
}
declare class NgForOf<T> {
ngForOf: Array<T>;
ngForTrackBy: (item: T, index: number) => any;
static ngTemplateGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
}
declare function Check_NgForOf<T>(options: {
ngForOf?: Array<T>,
ngForTrackBy?: (item: T, index: number) => any,
}): NgForOf<T>;
// <div *ngFor="let item of array">{{item.name}}</div>
declare class Cmp<T> {
array: T[];
}
declare function Check_Cmp<T>(options: {array?: T[]}): Cmp<T>;
function DoCheck_Cmp<T>(root: Cmp<T>): void {
let _d0 = Check_NgForOf({ ngForOf: root.array });
function DoCheck_Cmp_1<I>(root: Cmp<T> & { item: I }): void {
}
let _c0!: any;
if (NgForOf.ngTemplateGuard(_d0, _c0)) {
let _t0 = _c0.$implicit;
let _c1!: typeof root & { item: typeof _t0 };
DoCheck_Cmp_1(_c1);
}
}
declare interface NgForOfContext<T> {
$implicit: T;
index: number;
}
declare class NgForOf<T> {
ngForOf: T[];
static ngTemplateGuard<T>(value: T[], ctx: any): ctx is NgForOfContext<T>;
}
declare class NgIf {
static ngTemplateGuard<T>(value: T, ctx: any): value is NonNullable<T>;
}
class Cmp {
array: string[];
hidden: boolean|null|undefined;
}
class Bar {
prop: string;
}
function outer_typecheck(): void {
let _c0!: Cmp;
let _d0!: NgForOf<any>;
_d0.ngForOf = this.array;
let _g0: any;
if (NgForOf.ngTemplateGuard(_c0.array, _g0)) {
let foo = _g0.$implicit;
let idx = _g0.index;
function ngforof_typecheck() {
let _c1!: typeof _c0 & { foo: typeof foo, idx: typeof idx };
let _e1!: Bar;
_e1.prop = _c1.foo;
this.foo;
this.idx;
this.array;
}
}
_c0.hidden;
let _g1: any;
if (NgIf.ngTemplateGuard(_c0.hidden, _g1)) {
let _e0!: HTMLDivElement;
_e0.hidden = _c0.hidden;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment