Typechecking of context doesn't work with custom directives
See original GitHub issueI’m not sure if this is appropriate but this is basically just a duplicate of https://github.com/angular/vscode-ng-language-service/issues/650
Discussion within that issue seemed to suggest that the issue would be resolved using the ivy language service, however, I cant seem to get that to work and I’m just wondering about the status of the work toward resolving that issue or if there are additional steps I need to take to get it working. I’ve tried using the experimental ivy setting and leaving that option unchecked with no success.
In my scenario, the context is just
export class TemplateContext<T, U extends T[] = T[]> {
constructor(public $implicit: T, public ref: U){}
}
@Directive({
selector: '[spTemplateContent]'
})
export class TemplateContentDirective<T, U extends T[] = T[]> {
@Input()
spTemplateContentFrom: U
constructor(public content: TemplateRef<TemplateContext<T>>) {
}
static ngTemplateContextGuard<T, U extends T[] = T[]>(dir: TemplateContentDirective<T, U>, ctx: any):
ctx is TemplateContext<T, U> {
return true;
}
}
and using
<... *myDirective="let ctx; from: contentList" ...>
{{ctx}}
</...>
shows the type of “ctx” to be “any” but I would like it to show the type of an element of “contentList.” For instance, if contentList is a “MyCoolClass[]” then I would like ctx to show as type “MyCoolClass”
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (1 by maintainers)
@atscott sorry to keep commenting but actually just setting
"strictInputTypes": true
solved both issues for me (#650 and #1155) so I wanted to let you know. Thanks a bunch!@majellin24 Yes, with the Ivy Language Service enabled, #650 will work. The fix for #1155 is to have either
"strictTemplates": true
in theangularCompilerOptions
or both"fullTemplateTypeCheck": true
and"strictInputTypes": true
.