Skip to content

Commit baa0401

Browse files
committed
Fix microsoft#7173: Widen the type do the defualt export expression before writing it out.
1 parent 0cba37d commit baa0401

9 files changed

Lines changed: 134 additions & 1 deletion

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16240,7 +16240,7 @@ namespace ts {
1624016240
}
1624116241

1624216242
function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
16243-
const type = getTypeOfExpression(expr);
16243+
const type = getWidenedType(getTypeOfExpression(expr));
1624416244
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
1624516245
}
1624616246

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [declarationEmit_inferedDefaultExportType.ts]
2+
3+
// test.ts
4+
export default {
5+
foo: [],
6+
bar: undefined,
7+
baz: null
8+
}
9+
10+
//// [declarationEmit_inferedDefaultExportType.js]
11+
"use strict";
12+
exports.__esModule = true;
13+
exports["default"] = {
14+
foo: [],
15+
bar: undefined,
16+
baz: null
17+
};
18+
19+
20+
//// [declarationEmit_inferedDefaultExportType.d.ts]
21+
declare var _default: {
22+
foo: any[];
23+
bar: any;
24+
baz: any;
25+
};
26+
export default _default;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/declarationEmit_inferedDefaultExportType.ts ===
2+
3+
// test.ts
4+
export default {
5+
foo: [],
6+
>foo : Symbol(foo, Decl(declarationEmit_inferedDefaultExportType.ts, 2, 16))
7+
8+
bar: undefined,
9+
>bar : Symbol(bar, Decl(declarationEmit_inferedDefaultExportType.ts, 3, 10))
10+
>undefined : Symbol(undefined)
11+
12+
baz: null
13+
>baz : Symbol(baz, Decl(declarationEmit_inferedDefaultExportType.ts, 4, 17))
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/declarationEmit_inferedDefaultExportType.ts ===
2+
3+
// test.ts
4+
export default {
5+
>{ foo: [], bar: undefined, baz: null} : { foo: undefined[]; bar: undefined; baz: null; }
6+
7+
foo: [],
8+
>foo : undefined[]
9+
>[] : undefined[]
10+
11+
bar: undefined,
12+
>bar : undefined
13+
>undefined : undefined
14+
15+
baz: null
16+
>baz : null
17+
>null : null
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [declarationEmit_inferedDefaultExportType2.ts]
2+
3+
// test.ts
4+
export = {
5+
foo: [],
6+
bar: undefined,
7+
baz: null
8+
}
9+
10+
//// [declarationEmit_inferedDefaultExportType2.js]
11+
"use strict";
12+
module.exports = {
13+
foo: [],
14+
bar: undefined,
15+
baz: null
16+
};
17+
18+
19+
//// [declarationEmit_inferedDefaultExportType2.d.ts]
20+
declare var _default: {
21+
foo: any[];
22+
bar: any;
23+
baz: any;
24+
};
25+
export = _default;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/declarationEmit_inferedDefaultExportType2.ts ===
2+
3+
// test.ts
4+
export = {
5+
foo: [],
6+
>foo : Symbol(foo, Decl(declarationEmit_inferedDefaultExportType2.ts, 2, 10))
7+
8+
bar: undefined,
9+
>bar : Symbol(bar, Decl(declarationEmit_inferedDefaultExportType2.ts, 3, 10))
10+
>undefined : Symbol(undefined)
11+
12+
baz: null
13+
>baz : Symbol(baz, Decl(declarationEmit_inferedDefaultExportType2.ts, 4, 17))
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/declarationEmit_inferedDefaultExportType2.ts ===
2+
3+
// test.ts
4+
export = {
5+
>{ foo: [], bar: undefined, baz: null} : { foo: undefined[]; bar: undefined; baz: null; }
6+
7+
foo: [],
8+
>foo : undefined[]
9+
>[] : undefined[]
10+
11+
bar: undefined,
12+
>bar : undefined
13+
>undefined : undefined
14+
15+
baz: null
16+
>baz : null
17+
>null : null
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @declaration: true
2+
// @module: commonjs
3+
4+
// test.ts
5+
export default {
6+
foo: [],
7+
bar: undefined,
8+
baz: null
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @declaration: true
2+
// @module: commonjs
3+
4+
// test.ts
5+
export = {
6+
foo: [],
7+
bar: undefined,
8+
baz: null
9+
}

0 commit comments

Comments
 (0)