Created
September 1, 2018 01:06
-
-
Save alxhub/af982602e367a43564380b8368f4ba96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @Component({...}) | |
declare class Child<T> { | |
// @Input | |
value: T; | |
static ngTypeCheck<T>(inputs: { value?: T }): { $instance: Child<T> }; | |
} | |
// @Component({selector: '...', template: '{{child.value.name}}'}) | |
declare class Container<T extends { name: string }> { | |
// @ContentChild(Child) | |
child: Child<T>; | |
static ngTypeCheck<T extends { name: string }>(inputs: {}, project: { child?: Child<T> }): { $instance: Container<T> }; | |
} | |
function Container_tmpl<T extends { name: string }>(inputs: {}, project: { child?: Child<T> }) { | |
const c0 = Container.ngTypeCheck(inputs, project).$instance; | |
c0.child.value.name; | |
} | |
// @Component({selector: '...', template: '<container><child value="3"></child></container>'}) | |
declare class Consumer { | |
static ngTypeCheck(inputs: {}): { $instance: Consumer }; | |
} | |
function Consumer_tmpl(inputs: {}) { | |
const c0 = Consumer.ngTypeCheck(inputs); | |
const e1 = Child.ngTypeCheck({ value: 3 }).$instance; | |
const e0 = Container.ngTypeCheck({}, { child: e1 }).$instance; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @Component({...}) | |
declare class Child<T, U> { | |
// @Input | |
value: T; | |
//@Input | |
other: U; | |
static ngTypeCheck<T, U>(init: Partial<Pick<Child<T, U>, 'value'|'other'>>): { $instance: Child<T, U> }; | |
} | |
// @Component({selector: '...', template: '{{child.value.name}}'}) | |
declare class Container<T extends { name: string }> { | |
// @ContentChild(Child) | |
child: Child<T, any>; | |
static ngTypeCheck<T extends { name: string }>(init: Partial<Pick<Container<T>, 'child'>>): { $instance: Container<T> }; | |
} | |
function Container_tmpl<T extends { name: string }>(init: Partial<Pick<Container<T>, 'child'>>) { | |
const c0 = Container.ngTypeCheck(init).$instance; | |
c0.child.value.name; | |
} | |
// @Component({selector: '...', template: '<container><child value="3"></child></container>'}) | |
declare class Consumer { | |
static ngTypeCheck(init: Partial<Pick<Consumer, never>>): { $instance: Consumer }; | |
} | |
function Consumer_tmpl(init: Partial<Pick<Consumer, never>>) { | |
const c0 = Consumer.ngTypeCheck(init); | |
const e1 = Child.ngTypeCheck({ value: 3 }).$instance; | |
const e0 = Container.ngTypeCheck({child: e1 }).$instance; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
static ngTypeCheck<T>(inputs: { | |
ngForOf?: Array<T>, | |
ngForTrackBy?: (item: T, index: number) => any; | |
}): { | |
$instance: NgForOf<T>, | |
} | |
} | |
// <div *ngFor="let item of array">{{item.name}}</div> | |
class Cmp<T extends { name: string }> { | |
array: T[]; | |
static ngTypeCheck<T extends { name: string }>(inputs: { array?: T[] }): { $instance: Cmp<T> } { | |
return null!; | |
} | |
} | |
function t0<T extends { name: string }>(inputs: { | |
array?: T[], | |
}) { | |
let ctx: Cmp<T>; | |
const d0 = NgForOf.ngTypeCheck({ | |
ngForOf: ctx.array, | |
}).$instance; | |
let c1: {}; | |
if (NgForOf.ngTemplateGuard(d0, c1)) { | |
let t1ctx: typeof ctx & typeof c1; | |
function t1(c: typeof t1ctx) { | |
c.$implicit.name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment