Skip to content

Commit 0637148

Browse files
authored
fix(47946): check literal types in export assignments with declared JSDoc types (microsoft#47951)
1 parent e64f04b commit 0637148

5 files changed

+93
-2
lines changed

Diff for: src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9328,8 +9328,8 @@ namespace ts {
93289328
return isPrivateWithinAmbient(memberDeclaration);
93299329
}
93309330

9331-
function tryGetTypeFromEffectiveTypeNode(declaration: Declaration) {
9332-
const typeNode = getEffectiveTypeAnnotationNode(declaration);
9331+
function tryGetTypeFromEffectiveTypeNode(node: Node) {
9332+
const typeNode = getEffectiveTypeAnnotationNode(node);
93339333
if (typeNode) {
93349334
return getTypeFromTypeNode(typeNode);
93359335
}
@@ -26740,6 +26740,8 @@ namespace ts {
2674026740
}
2674126741
case SyntaxKind.NonNullExpression:
2674226742
return getContextualType(parent as NonNullExpression, contextFlags);
26743+
case SyntaxKind.ExportAssignment:
26744+
return tryGetTypeFromEffectiveTypeNode(parent as ExportAssignment);
2674326745
case SyntaxKind.JsxExpression:
2674426746
return getContextualTypeForJsxExpression(parent as JsxExpression);
2674526747
case SyntaxKind.JsxAttribute:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.ts] ////
2+
3+
//// [checkJsdocTypeTagOnExportAssignment8.js]
4+
5+
//// [a.js]
6+
/**
7+
* @typedef Foo
8+
* @property {string} a
9+
* @property {'b'} b
10+
*/
11+
12+
/** @type {Foo} */
13+
export default {
14+
a: 'a',
15+
b: 'b'
16+
}
17+
18+
19+
//// [checkJsdocTypeTagOnExportAssignment8.js]
20+
//// [a.js]
21+
"use strict";
22+
/**
23+
* @typedef Foo
24+
* @property {string} a
25+
* @property {'b'} b
26+
*/
27+
exports.__esModule = true;
28+
/** @type {Foo} */
29+
exports["default"] = {
30+
a: 'a',
31+
b: 'b'
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.js ===
2+
3+
No type information for this code.=== tests/cases/compiler/a.js ===
4+
/**
5+
* @typedef Foo
6+
* @property {string} a
7+
* @property {'b'} b
8+
*/
9+
10+
/** @type {Foo} */
11+
export default {
12+
a: 'a',
13+
>a : Symbol(a, Decl(a.js, 7, 16))
14+
15+
b: 'b'
16+
>b : Symbol(b, Decl(a.js, 8, 11))
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.js ===
2+
3+
No type information for this code.=== tests/cases/compiler/a.js ===
4+
/**
5+
* @typedef Foo
6+
* @property {string} a
7+
* @property {'b'} b
8+
*/
9+
10+
/** @type {Foo} */
11+
export default {
12+
>{ a: 'a', b: 'b'} : { a: string; b: "b"; }
13+
14+
a: 'a',
15+
>a : string
16+
>'a' : "a"
17+
18+
b: 'b'
19+
>b : "b"
20+
>'b' : "b"
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @outDir: ./out
4+
// @filename: checkJsdocTypeTagOnExportAssignment8.js
5+
6+
// @Filename: a.js
7+
/**
8+
* @typedef Foo
9+
* @property {string} a
10+
* @property {'b'} b
11+
*/
12+
13+
/** @type {Foo} */
14+
export default {
15+
a: 'a',
16+
b: 'b'
17+
}

0 commit comments

Comments
 (0)