Skip to content

Leverage existing function for choosing spread validity (#21564) #21575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17585,7 +17585,7 @@ namespace ts {
const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
anonymousSymbol.type = defaultContainingObject;
synthType.syntheticType = (type.flags & TypeFlags.StructuredType && type.symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject;
synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject;
}
else {
synthType.syntheticType = type;
Expand Down
27 changes: 27 additions & 0 deletions tests/baselines/reference/esModuleIntersectionCrash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/esModuleIntersectionCrash.ts] ////

//// [mod.d.ts]
export = modObj;
declare const modObj: modObj.A & modObj.B;
declare namespace modObj {
interface A { (): void; a: string; }
interface B { (x: string): void; b: string; }
}
//// [idx.ts]
import * as mod from "./mod";
mod.a;
mod.b;

//// [idx.js]
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}
exports.__esModule = true;
var mod = __importStar(require("./mod"));
mod.a;
mod.b;
37 changes: 37 additions & 0 deletions tests/baselines/reference/esModuleIntersectionCrash.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/mod.d.ts ===
export = modObj;
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))

declare const modObj: modObj.A & modObj.B;
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
>A : Symbol(modObj.A, Decl(mod.d.ts, 2, 26))
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
>B : Symbol(modObj.B, Decl(mod.d.ts, 3, 40))

declare namespace modObj {
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))

interface A { (): void; a: string; }
>A : Symbol(A, Decl(mod.d.ts, 2, 26))
>a : Symbol(A.a, Decl(mod.d.ts, 3, 27))

interface B { (x: string): void; b: string; }
>B : Symbol(B, Decl(mod.d.ts, 3, 40))
>x : Symbol(x, Decl(mod.d.ts, 4, 19))
>b : Symbol(B.b, Decl(mod.d.ts, 4, 36))
}
=== tests/cases/compiler/idx.ts ===
import * as mod from "./mod";
>mod : Symbol(mod, Decl(idx.ts, 0, 6))

mod.a;
>mod.a : Symbol(mod.A.a, Decl(mod.d.ts, 3, 27))
>mod : Symbol(mod, Decl(idx.ts, 0, 6))
>a : Symbol(mod.A.a, Decl(mod.d.ts, 3, 27))

mod.b;
>mod.b : Symbol(mod.B.b, Decl(mod.d.ts, 4, 36))
>mod : Symbol(mod, Decl(idx.ts, 0, 6))
>b : Symbol(mod.B.b, Decl(mod.d.ts, 4, 36))

37 changes: 37 additions & 0 deletions tests/baselines/reference/esModuleIntersectionCrash.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/mod.d.ts ===
export = modObj;
>modObj : modObj.A & modObj.B

declare const modObj: modObj.A & modObj.B;
>modObj : modObj.A & modObj.B
>modObj : any
>A : modObj.A
>modObj : any
>B : modObj.B

declare namespace modObj {
>modObj : A & B

interface A { (): void; a: string; }
>A : A
>a : string

interface B { (x: string): void; b: string; }
>B : B
>x : string
>b : string
}
=== tests/cases/compiler/idx.ts ===
import * as mod from "./mod";
>mod : { default: mod.A & mod.B; a: string; b: string; }

mod.a;
>mod.a : string
>mod : { default: mod.A & mod.B; a: string; b: string; }
>a : string

mod.b;
>mod.b : string
>mod : { default: mod.A & mod.B; a: string; b: string; }
>b : string

12 changes: 12 additions & 0 deletions tests/cases/compiler/esModuleIntersectionCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @esModuleInterop: true
// @filename: mod.d.ts
export = modObj;
declare const modObj: modObj.A & modObj.B;
declare namespace modObj {
interface A { (): void; a: string; }
interface B { (x: string): void; b: string; }
}
// @filename: idx.ts
import * as mod from "./mod";
mod.a;
mod.b;