fix(ivy): do not always accept undefined
for directive inputs (#33066)
Prior to this change, the template type checker would always allow a value of type `undefined` to be passed into a directive's inputs, even if the input's type did not allow for it. This was due to how the type constructor for a directive was generated, where a `Partial` mapped type was used to allow for inputs to be unset. This essentially introduces the `undefined` type as acceptable type for all inputs. This commit removes the `Partial` type from the type constructor, which means that we can no longer omit any properties that were unset. Instead, any properties that are not set will still be included in the type constructor call, having their value assigned to `any`. Before: ```typescript class NgForOf<T> { static ngTypeCtor<T>(init: Partial<Pick<NgForOf<T>, 'ngForOf'|'ngForTrackBy'|'ngForTemplate'>>): NgForOf<T>; } NgForOf.ngTypeCtor(init: {ngForOf: ['foo', 'bar']}); ``` After: ```typescript class NgForOf<T> { static ngTypeCtor<T>(init: Pick<NgForOf<T>, 'ngForOf'|'ngForTrackBy'|'ngForTemplate'>): NgForOf<T>; } NgForOf.ngTypeCtor(init: { ngForOf: ['foo', 'bar'], ngForTrackBy: null as any, ngForTemplate: null as any, }); ``` This change only affects generated type check code, the generated runtime code is not affected. Fixes #32690 Resolves FW-1606 PR Close #33066
This commit is contained in:
@ -336,12 +336,10 @@ export declare class CommonModule {
|
||||
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(2);
|
||||
expect(diags[0].messageText)
|
||||
.toBe(`Type 'number' is not assignable to type 'string | undefined'.`);
|
||||
expect(diags[0].messageText).toBe(`Type 'number' is not assignable to type 'string'.`);
|
||||
expect(diags[0].start).toEqual(386);
|
||||
expect(diags[0].length).toEqual(14);
|
||||
expect(diags[1].messageText)
|
||||
.toBe(`Type 'number' is not assignable to type 'boolean | undefined'.`);
|
||||
expect(diags[1].messageText).toBe(`Type 'number' is not assignable to type 'boolean'.`);
|
||||
expect(diags[1].start).toEqual(401);
|
||||
expect(diags[1].length).toEqual(15);
|
||||
});
|
||||
|
Reference in New Issue
Block a user