fix(ivy): allow directive inheritance in strict mode (#28634)

For TypeScript compilation units that have the "strictFunctionTypes"
option enabled, an error would be produced for Ivy's definition fields
in declaration files in the case of inheritance across directives or
pipes.

This change loosens the definition types to allow for subtypes of the
defined type where necessary.

A test package that has the "strict" option enabled verifies that we
won't regress in environments where strict type checking is enabled.

Fixes #28079

PR Close #28634
This commit is contained in:
JoostK
2019-02-09 22:51:29 +01:00
committed by Miško Hevery
parent 91b7152852
commit 06ec95f2ef
8 changed files with 107 additions and 19 deletions

View File

@ -184,7 +184,7 @@ describe('di', () => {
consts: 0,
vars: 0,
factory: () => new Comp(directiveInject(DirB)),
template: (ctx: any, fm: boolean) => {}
template: (rf: RenderFlags, ctx: Comp) => {}
});
}

View File

@ -7,7 +7,7 @@
*/
import {ElementRef, Inject, InjectionToken, QueryList, ɵAttributeMarker as AttributeMarker} from '../../src/core';
import {ComponentDef, DirectiveDef, InheritDefinitionFeature, NgOnChangesFeature, ProvidersFeature, RenderFlags, allocHostVars, bind, contentQuery, defineBase, defineComponent, defineDirective, directiveInject, element, elementEnd, elementProperty, elementStart, load, loadContentQuery, loadViewQuery, queryRefresh, viewQuery} from '../../src/render3/index';
import {allocHostVars, bind, ComponentDef, contentQuery, defineBase, defineComponent, defineDirective, DirectiveDef, directiveInject, element, elementEnd, elementProperty, elementStart, InheritDefinitionFeature, load, loadContentQuery, loadViewQuery, NgOnChangesFeature, ProvidersFeature, queryRefresh, RenderFlags, viewQuery,} from '../../src/render3/index';
import {ComponentFixture, createComponent, getDirectiveOnNode} from './render_util';
@ -457,8 +457,8 @@ describe('InheritDefinitionFeature', () => {
consts: 0,
vars: 0,
selectors: [['', 'subDir', '']],
viewQuery: (directiveIndex: number, elementIndex: number) => {
log.push(['sub', directiveIndex, elementIndex]);
viewQuery: (rf: RenderFlags, ctx: SubComponent) => {
log.push(['sub', rf, ctx]);
},
factory: () => new SubComponent(),
features: [InheritDefinitionFeature]
@ -469,9 +469,10 @@ describe('InheritDefinitionFeature', () => {
const context = {foo: 'bar'};
subDef.viewQuery !(1, context);
subDef.viewQuery !(RenderFlags.Create, context);
expect(log).toEqual([['super', 1, context], ['sub', 1, context]]);
expect(log).toEqual(
[['super', RenderFlags.Create, context], ['sub', RenderFlags.Create, context]]);
});