Skip to content

Commit

Permalink
Fixed type not showing correctly in template with Ivy enabled (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Arnd <[email protected]>
  • Loading branch information
arndwestermann and Arnd authored Mar 17, 2021
1 parent 2342d53 commit 125e4cf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions projects/ngx-var/src/lib/ngx-var.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,30 @@ export class NgxVarDirective<T = unknown> implements OnInit {
ngOnInit() {
this._vcr.createEmbeddedView(this._templateRef, this._context);
}

/** @internal */
public static ngxVarUseIfTypeGuard: void;

/**
* Assert the correct type of the expression bound to the `ngxVar` input within the template.
*
* The presence of this static field is a signal to the Ivy template type check compiler that
* when the `ngxVar` structural directive renders its template, the type of the expression bound
* to `ngxVar` should be narrowed in some way. For `ngxVar`, the binding expression itself is used to
* narrow its type, which allows the strictNullChecks feature of TypeScript to work with `ngxVar`.
*/
static ngTemplateGuard_ngxVar: 'binding';

/**
* Asserts the correct type of the context for the template that `ngxVar` will render.
*
* The presence of this method is a signal to the Ivy template type-check compiler that the
* `ngxVar` structural directive renders its template with a specific context type.
*/
static ngTemplateContextGuard<T>(
dir: NgxVarDirective<T>,
ctx: any
): ctx is Context<Exclude<T, false | 0 | '' | null | undefined>> {
return true;
}
}

0 comments on commit 125e4cf

Please sign in to comment.