Skip to content

Commit 8c1a7ce

Browse files
authored
Leverage existing function for choosing spread validity (#21564) (#21575)
1 parent 9e0d8c3 commit 8c1a7ce

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17585,7 +17585,7 @@ namespace ts {
1758517585
const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
1758617586
const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
1758717587
anonymousSymbol.type = defaultContainingObject;
17588-
synthType.syntheticType = (type.flags & TypeFlags.StructuredType && type.symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject;
17588+
synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject;
1758917589
}
1759017590
else {
1759117591
synthType.syntheticType = type;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/esModuleIntersectionCrash.ts] ////
2+
3+
//// [mod.d.ts]
4+
export = modObj;
5+
declare const modObj: modObj.A & modObj.B;
6+
declare namespace modObj {
7+
interface A { (): void; a: string; }
8+
interface B { (x: string): void; b: string; }
9+
}
10+
//// [idx.ts]
11+
import * as mod from "./mod";
12+
mod.a;
13+
mod.b;
14+
15+
//// [idx.js]
16+
"use strict";
17+
var __importStar = (this && this.__importStar) || function (mod) {
18+
if (mod && mod.__esModule) return mod;
19+
var result = {};
20+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
21+
result["default"] = mod;
22+
return result;
23+
}
24+
exports.__esModule = true;
25+
var mod = __importStar(require("./mod"));
26+
mod.a;
27+
mod.b;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/mod.d.ts ===
2+
export = modObj;
3+
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
4+
5+
declare const modObj: modObj.A & modObj.B;
6+
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
7+
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
8+
>A : Symbol(modObj.A, Decl(mod.d.ts, 2, 26))
9+
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
10+
>B : Symbol(modObj.B, Decl(mod.d.ts, 3, 40))
11+
12+
declare namespace modObj {
13+
>modObj : Symbol(modObj, Decl(mod.d.ts, 1, 13), Decl(mod.d.ts, 1, 42))
14+
15+
interface A { (): void; a: string; }
16+
>A : Symbol(A, Decl(mod.d.ts, 2, 26))
17+
>a : Symbol(A.a, Decl(mod.d.ts, 3, 27))
18+
19+
interface B { (x: string): void; b: string; }
20+
>B : Symbol(B, Decl(mod.d.ts, 3, 40))
21+
>x : Symbol(x, Decl(mod.d.ts, 4, 19))
22+
>b : Symbol(B.b, Decl(mod.d.ts, 4, 36))
23+
}
24+
=== tests/cases/compiler/idx.ts ===
25+
import * as mod from "./mod";
26+
>mod : Symbol(mod, Decl(idx.ts, 0, 6))
27+
28+
mod.a;
29+
>mod.a : Symbol(mod.A.a, Decl(mod.d.ts, 3, 27))
30+
>mod : Symbol(mod, Decl(idx.ts, 0, 6))
31+
>a : Symbol(mod.A.a, Decl(mod.d.ts, 3, 27))
32+
33+
mod.b;
34+
>mod.b : Symbol(mod.B.b, Decl(mod.d.ts, 4, 36))
35+
>mod : Symbol(mod, Decl(idx.ts, 0, 6))
36+
>b : Symbol(mod.B.b, Decl(mod.d.ts, 4, 36))
37+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/mod.d.ts ===
2+
export = modObj;
3+
>modObj : modObj.A & modObj.B
4+
5+
declare const modObj: modObj.A & modObj.B;
6+
>modObj : modObj.A & modObj.B
7+
>modObj : any
8+
>A : modObj.A
9+
>modObj : any
10+
>B : modObj.B
11+
12+
declare namespace modObj {
13+
>modObj : A & B
14+
15+
interface A { (): void; a: string; }
16+
>A : A
17+
>a : string
18+
19+
interface B { (x: string): void; b: string; }
20+
>B : B
21+
>x : string
22+
>b : string
23+
}
24+
=== tests/cases/compiler/idx.ts ===
25+
import * as mod from "./mod";
26+
>mod : { default: mod.A & mod.B; a: string; b: string; }
27+
28+
mod.a;
29+
>mod.a : string
30+
>mod : { default: mod.A & mod.B; a: string; b: string; }
31+
>a : string
32+
33+
mod.b;
34+
>mod.b : string
35+
>mod : { default: mod.A & mod.B; a: string; b: string; }
36+
>b : string
37+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @esModuleInterop: true
2+
// @filename: mod.d.ts
3+
export = modObj;
4+
declare const modObj: modObj.A & modObj.B;
5+
declare namespace modObj {
6+
interface A { (): void; a: string; }
7+
interface B { (x: string): void; b: string; }
8+
}
9+
// @filename: idx.ts
10+
import * as mod from "./mod";
11+
mod.a;
12+
mod.b;

0 commit comments

Comments
 (0)