test(compiler-cli): load type declarations from fake_common (#41995)

The ngtsc test targets have fake declarations files for `@angular/core`
and `@angular/common` and the template type checking tests can leverage
the fake common declarations instead of declaring its own types.

PR Close #41995
This commit is contained in:
JoostK 2021-05-07 21:48:06 +02:00 committed by Jessica Janiuk
parent bd1836b999
commit 481540dd4e
3 changed files with 13 additions and 63 deletions

View File

@ -56,6 +56,7 @@ export declare class NgIf<T = unknown> {
'ngIfElse': 'ngIfElse';
}
, {}, never > ;
static ngTemplateGuard_ngIf: 'binding';
static ngTemplateContextGuard<T>(dir: NgIf<T>, ctx: any):
ctx is NgIfContext<Exclude<T, false|0|''|null|undefined>>;
}
@ -83,8 +84,16 @@ export declare class DatePipe {
static ɵpipe: ɵɵPipeDeclaration<DatePipe, 'date'>;
}
export declare class IndexPipe {
transform<T>(value: T[], index: number): T;
static ɵpipe: ɵɵPipeDeclaration<IndexPipe, 'index'>;
}
export declare class CommonModule {
static ɵmod: ɵɵNgModuleDeclaration<
CommonModule, [typeof NgForOf, typeof NgIf, typeof DatePipe, typeof NgTemplateOutlet], never,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof NgTemplateOutlet]>;
CommonModule,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof IndexPipe, typeof NgTemplateOutlet],
never,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof IndexPipe, typeof NgTemplateOutlet]>;
}

View File

@ -26,6 +26,7 @@ jasmine_node_test(
timeout = "long",
bootstrap = ["//tools/testing:node_no_angular_es5"],
data = [
"//packages/compiler-cli/src/ngtsc/testing/fake_common:npm_package",
"//packages/compiler-cli/src/ngtsc/testing/fake_core:npm_package",
],
shard_count = 4,

View File

@ -15,7 +15,7 @@ import {expectCompleteReuse, loadStandardTestFiles} from '../../src/ngtsc/testin
import {NgtscTestEnvironment} from './env';
const testFiles = loadStandardTestFiles();
const testFiles = loadStandardTestFiles({fakeCore: true, fakeCommon: true});
runInEachFileSystem(() => {
describe('ngtsc type checking', () => {
@ -24,66 +24,6 @@ runInEachFileSystem(() => {
beforeEach(() => {
env = NgtscTestEnvironment.setup(testFiles);
env.tsconfig({fullTemplateTypeCheck: true});
env.write('node_modules/@angular/common/index.d.ts', `
import * as i0 from '@angular/core';
export declare class NgForOfContext<T, U extends i0.NgIterable<T> = i0.NgIterable<T>> {
$implicit: T;
count: number;
readonly even: boolean;
readonly first: boolean;
index: number;
readonly last: boolean;
ngForOf: U;
readonly odd: boolean;
constructor($implicit: T, ngForOf: U, index: number, count: number);
}
export declare class IndexPipe {
transform<T>(value: T[], index: number): T;
static ɵpipe: i0.ɵPipeDeclaration<IndexPipe, 'index'>;
}
export declare class SlicePipe {
transform<T>(value: ReadonlyArray<T>, start: number, end?: number): Array<T>;
transform(value: string, start: number, end?: number): string;
transform(value: null, start: number, end?: number): null;
transform(value: undefined, start: number, end?: number): undefined;
transform(value: any, start: number, end?: number): any;
static ɵpipe: i0.ɵPipeDeclaration<SlicePipe, 'slice'>;
}
export declare class NgForOf<T, U extends i0.NgIterable<T> = i0.NgIterable<T>> implements DoCheck {
ngForOf: (U & i0.NgIterable<T>) | undefined | null;
ngForTemplate: TemplateRef<NgForOfContext<T, U>>;
ngForTrackBy: TrackByFunction<T>;
constructor(_viewContainer: ViewContainerRef, _template: TemplateRef<NgForOfContext<T, U>>, _differs: IterableDiffers);
ngDoCheck(): void;
static ngTemplateContextGuard<T, U extends i0.NgIterable<T>>(dir: NgForOf<T, U>, ctx: any): ctx is NgForOfContext<T, U>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgForOf<any>, '[ngFor][ngForOf]', never, {'ngForOf': 'ngForOf'}, {}, never>;
}
export declare class NgIf<T = unknown> {
ngIf: T;
ngIfElse: TemplateRef<NgIfContext<T>> | null;
ngIfThen: TemplateRef<NgIfContext<T>> | null;
constructor(_viewContainer: ViewContainerRef, templateRef: TemplateRef<NgIfContext<T>>);
static ngTemplateGuard_ngIf: 'binding';
static ngTemplateContextGuard<T>(dir: NgIf<T>, ctx: any): ctx is NgIfContext<Exclude<T, false | 0 | "" | null | undefined>>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgIf<any>, '[ngIf]', never, {'ngIf': 'ngIf'}, {}, never>;
}
export declare class NgIfContext<T = unknown> {
$implicit: T;
ngIf: T;
}
export declare class CommonModule {
static ɵmod: i0.ɵɵNgModuleDeclaration<CommonModule, [typeof NgIf, typeof NgForOf, typeof IndexPipe, typeof SlicePipe], never, [typeof NgIf, typeof NgForOf, typeof IndexPipe, typeof SlicePipe]>;
}
`);
env.write('node_modules/@angular/animations/index.d.ts', `
export declare class AnimationEvent {
element: any;