feat(compiler-cli): add support for TypeScript 4.0 (#38076)

With this change we add support for TypeScript 4.0

PR Close #38076
This commit is contained in:
Alan Agius
2020-07-15 12:21:04 +02:00
committed by Misko Hevery
parent 201a546af8
commit 0fc44e0436
37 changed files with 315 additions and 141 deletions

View File

@ -787,7 +787,7 @@ describe('ng type checker', () => {
it('should report an invalid call to a pipe', () => {
rejectOnlyWithFullTemplateTypeCheck(
'<div>{{"hello" | aPipe}}</div>',
`Argument of type '"hello"' is not assignable to parameter of type 'number'.`, '0:5');
`Argument of type 'string' is not assignable to parameter of type 'number'.`, '0:5');
});
it('should report an invalid property on an exportAs directive', () => {
rejectOnlyWithFullTemplateTypeCheck(

View File

@ -136,7 +136,7 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(1);
expect(diags[0].messageText).toEqual(`Type '"2"' is not assignable to type 'number'.`);
expect(diags[0].messageText).toEqual(`Type 'string' is not assignable to type 'number'.`);
// The reported error code should be in the TS error space, not a -99 "NG" code.
expect(diags[0].code).toBeGreaterThan(0);
});
@ -168,8 +168,8 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '"2"' is not assignable to type 'number'.`);
expect(diags[1].messageText).toEqual(`Type '"2"' is not assignable to type 'number'.`);
expect(diags[0].messageText).toEqual(`Type 'string' is not assignable to type 'number'.`);
expect(diags[1].messageText).toEqual(`Type 'string' is not assignable to type 'number'.`);
});
it('should support inputs and outputs with names that are not JavaScript identifiers', () => {
@ -204,7 +204,7 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '2' is not assignable to type 'string'.`);
expect(diags[0].messageText).toEqual(`Type 'number' is not assignable to type 'string'.`);
expect(diags[1].messageText)
.toEqual(`Argument of type 'string' is not assignable to parameter of type 'number'.`);
});
@ -380,7 +380,7 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '1' is not assignable to type 'string'.`);
expect(diags[0].messageText).toEqual(`Type 'number' is not assignable to type 'string'.`);
expect(diags[1].messageText)
.toEqual(`Property 'invalid' does not exist on type 'TestCmp'.`);
});
@ -390,7 +390,7 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '1' is not assignable to type 'string'.`);
expect(diags[0].messageText).toEqual(`Type 'number' is not assignable to type 'string'.`);
expect(diags[1].messageText)
.toEqual(`Property 'invalid' does not exist on type 'TestCmp'.`);
});
@ -716,8 +716,8 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '""' is not assignable to type 'boolean'.`);
expect(diags[1].messageText).toEqual(`Type '"3"' is not assignable to type 'number'.`);
expect(diags[0].messageText).toEqual(`Type 'string' is not assignable to type 'boolean'.`);
expect(diags[1].messageText).toEqual(`Type 'string' is not assignable to type 'number'.`);
});
it('should produce an error for text attributes when overall strictness is enabled', () => {
@ -725,8 +725,8 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(2);
expect(diags[0].messageText).toEqual(`Type '""' is not assignable to type 'boolean'.`);
expect(diags[1].messageText).toEqual(`Type '"3"' is not assignable to type 'number'.`);
expect(diags[0].messageText).toEqual(`Type 'string' is not assignable to type 'boolean'.`);
expect(diags[1].messageText).toEqual(`Type 'string' is not assignable to type 'number'.`);
});
it('should not produce an error for text attributes when not enabled', () => {
@ -1119,7 +1119,7 @@ export declare class AnimationEvent {
const allErrors = [
`'does_not_exist' does not exist on type '{ name: string; }'`,
`Expected 2 arguments, but got 3.`,
`Argument of type '"test"' is not assignable to parameter of type 'number'`,
`Argument of type 'string' is not assignable to parameter of type 'number'`,
`Argument of type '{ name: string; }' is not assignable to parameter of type 'unknown[]'`,
];
@ -1241,11 +1241,11 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(3);
expect(diags[0].messageText).toBe(`Type 'true' is not assignable to type 'number'.`);
expect(diags[0].messageText).toBe(`Type 'boolean' is not assignable to type 'number'.`);
expect(getSourceCodeForDiagnostic(diags[0])).toEqual('[fromAbstract]="true"');
expect(diags[1].messageText).toBe(`Type '3' is not assignable to type 'string'.`);
expect(diags[1].messageText).toBe(`Type 'number' is not assignable to type 'string'.`);
expect(getSourceCodeForDiagnostic(diags[1])).toEqual('[fromBase]="3"');
expect(diags[2].messageText).toBe(`Type '4' is not assignable to type 'boolean'.`);
expect(diags[2].messageText).toBe(`Type 'number' is not assignable to type 'boolean'.`);
expect(getSourceCodeForDiagnostic(diags[2])).toEqual('[fromChild]="4"');
});
@ -1298,11 +1298,11 @@ export declare class AnimationEvent {
const diags = env.driveDiagnostics();
expect(diags.length).toBe(3);
expect(diags[0].messageText).toBe(`Type 'true' is not assignable to type 'number'.`);
expect(diags[0].messageText).toBe(`Type 'boolean' is not assignable to type 'number'.`);
expect(getSourceCodeForDiagnostic(diags[0])).toEqual('[fromAbstract]="true"');
expect(diags[1].messageText).toBe(`Type '3' is not assignable to type 'string'.`);
expect(diags[1].messageText).toBe(`Type 'number' is not assignable to type 'string'.`);
expect(getSourceCodeForDiagnostic(diags[1])).toEqual('[fromBase]="3"');
expect(diags[2].messageText).toBe(`Type '4' is not assignable to type 'boolean'.`);
expect(diags[2].messageText).toBe(`Type 'number' is not assignable to type 'boolean'.`);
expect(getSourceCodeForDiagnostic(diags[2])).toEqual('[fromChild]="4"');
});

View File

@ -584,7 +584,7 @@ describe('downlevel decorator transform', () => {
const visitNode = (node: ts.Node): ts.Node => {
if (ts.isClassDeclaration(node) || ts.isClassElement(node)) {
const cloned = ts.getMutableClone(node);
cloned.decorators = undefined;
(cloned.decorators as undefined) = undefined;
return cloned;
}
return ts.visitEachChild(node, visitNode, context);

View File

@ -492,11 +492,11 @@ describe('ng program', () => {
.toBe(true);
switch (checks.shouldBe) {
case ShouldBe.Empty:
expect(writeData!.data).toMatch(/^(\s*\/\*([^*]|\*[^/])*\*\/\s*)?$/);
expect(writeData!.data).toMatch(/^(\s*\/\*([^*]|\*[^\/])*\*\/\s*)?$/);
break;
case ShouldBe.EmptyExport:
expect(writeData!.data)
.toMatch(/^((\s*\/\*([^*]|\*[^/])*\*\/\s*)|(\s*export\s*{\s*}\s*;\s*)|())$/);
.toMatch(/^((\s*\/\*([^*]|\*[^\/])*\*\/\s*)|(\s*export\s*{\s*};\s*))$/m);
break;
case ShouldBe.NoneEmpty:
expect(writeData!.data).not.toBe('');
@ -505,12 +505,14 @@ describe('ng program', () => {
}
assertGenFile(
'built/src/util.ngfactory.js', {originalFileName: 'src/util.ts', shouldBe: ShouldBe.Empty});
'built/src/util.ngfactory.js',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
assertGenFile(
'built/src/util.ngfactory.d.ts',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
assertGenFile(
'built/src/util.ngsummary.js', {originalFileName: 'src/util.ts', shouldBe: ShouldBe.Empty});
'built/src/util.ngsummary.js',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
assertGenFile(
'built/src/util.ngsummary.d.ts',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
@ -987,7 +989,8 @@ describe('ng program', () => {
const errorDiags =
program1.emit().diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
expect(stripAnsi(formatDiagnostics(errorDiags)))
.toContain(`src/main.ts:5:13 - error TS2322: Type '1' is not assignable to type 'string'.`);
.toContain(
`src/main.ts:5:13 - error TS2322: Type 'number' is not assignable to type 'string'.`);
expect(stripAnsi(formatDiagnostics(errorDiags)))
.toContain(
`src/main.html:1:1 - error TS100: Property 'nonExistent' does not exist on type 'MyComp'.`);