fix(47946): check literal types in export assignments with declared JSDoc types (#47951)

This commit is contained in:
Oleksandr T
2022-03-01 14:44:36 -08:00
committed by GitHub
parent e64f04bd8c
commit 063714886e
5 changed files with 93 additions and 2 deletions
+4 -2
View File
@@ -9328,8 +9328,8 @@ namespace ts {
return isPrivateWithinAmbient(memberDeclaration);
}
function tryGetTypeFromEffectiveTypeNode(declaration: Declaration) {
const typeNode = getEffectiveTypeAnnotationNode(declaration);
function tryGetTypeFromEffectiveTypeNode(node: Node) {
const typeNode = getEffectiveTypeAnnotationNode(node);
if (typeNode) {
return getTypeFromTypeNode(typeNode);
}
@@ -26740,6 +26740,8 @@ namespace ts {
}
case SyntaxKind.NonNullExpression:
return getContextualType(parent as NonNullExpression, contextFlags);
case SyntaxKind.ExportAssignment:
return tryGetTypeFromEffectiveTypeNode(parent as ExportAssignment);
case SyntaxKind.JsxExpression:
return getContextualTypeForJsxExpression(parent as JsxExpression);
case SyntaxKind.JsxAttribute:
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.ts] ////
//// [checkJsdocTypeTagOnExportAssignment8.js]
//// [a.js]
/**
* @typedef Foo
* @property {string} a
* @property {'b'} b
*/
/** @type {Foo} */
export default {
a: 'a',
b: 'b'
}
//// [checkJsdocTypeTagOnExportAssignment8.js]
//// [a.js]
"use strict";
/**
* @typedef Foo
* @property {string} a
* @property {'b'} b
*/
exports.__esModule = true;
/** @type {Foo} */
exports["default"] = {
a: 'a',
b: 'b'
};
@@ -0,0 +1,18 @@
=== tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.js ===
No type information for this code.=== tests/cases/compiler/a.js ===
/**
* @typedef Foo
* @property {string} a
* @property {'b'} b
*/
/** @type {Foo} */
export default {
a: 'a',
>a : Symbol(a, Decl(a.js, 7, 16))
b: 'b'
>b : Symbol(b, Decl(a.js, 8, 11))
}
@@ -0,0 +1,22 @@
=== tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.js ===
No type information for this code.=== tests/cases/compiler/a.js ===
/**
* @typedef Foo
* @property {string} a
* @property {'b'} b
*/
/** @type {Foo} */
export default {
>{ a: 'a', b: 'b'} : { a: string; b: "b"; }
a: 'a',
>a : string
>'a' : "a"
b: 'b'
>b : "b"
>'b' : "b"
}
@@ -0,0 +1,17 @@
// @allowJs: true
// @checkJs: true
// @outDir: ./out
// @filename: checkJsdocTypeTagOnExportAssignment8.js
// @Filename: a.js
/**
* @typedef Foo
* @property {string} a
* @property {'b'} b
*/
/** @type {Foo} */
export default {
a: 'a',
b: 'b'
}