Skip to content

Commit

Permalink
fix: work around 'noImplicityAny' incompatibility due to ts3.7 update
Browse files Browse the repository at this point in the history
Typescript 3.7 now emits d.ts files for getters differently than prior versions,
and there seems to be a bug in how it strips private types without replacing them
with explicit 'any' type. This then leads to compilation failures in projects compiled
against our packages that don't have skipLibCheck turned on but do have strict or
noImplicitAny check on.

I'm working around this by marking the affected getters as @internal and
adding a test to prevent future regressions.

I believe this is a TypeScript bug, and I filed a bug report:
microsoft/TypeScript#36216
  • Loading branch information
IgorMinar committed Jan 16, 2020
1 parent a673571 commit 355ecdf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/compiler/src/output/abstract_emitter.ts
Expand Up @@ -36,6 +36,10 @@ export class EmitterVisitorContext {

constructor(private _indent: number) { this._lines = [new _EmittedLine(_indent)]; }

/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get _currentLine(): _EmittedLine { return this._lines[this._lines.length - 1]; }

println(from?: {sourceSpan: ParseSourceSpan | null}|null, lastPart: string = ''): void {
Expand Down Expand Up @@ -169,6 +173,10 @@ export class EmitterVisitorContext {
return null;
}

/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get sourceLines(): _EmittedLine[] {
if (this._lines.length && this._lines[this._lines.length - 1].parts.length === 0) {
return this._lines.slice(0, -1);
Expand Down
4 changes: 4 additions & 0 deletions packages/compiler/src/output/source_map.ts
Expand Up @@ -74,6 +74,10 @@ export class SourceMapGenerator {
return this;
}

/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get currentLine(): Segment[]|null { return this.lines.slice(-1)[0]; }

toJSON(): SourceMap|null {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/testing/src/r3_test_bed.ts
Expand Up @@ -351,13 +351,21 @@ export class TestBedRender3 implements TestBed {
return fixture;
}

/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get compiler(): R3TestBedCompiler {
if (this._compiler === null) {
throw new Error(`Need to call TestBed.initTestEnvironment() first`);
}
return this._compiler;
}

/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get testModuleRef(): NgModuleRef<any> {
if (this._testModuleRef === null) {
this._testModuleRef = this.compiler.finalize();
Expand Down

0 comments on commit 355ecdf

Please sign in to comment.