Skip to content

Commit

Permalink
fix(47946): check literal types in export assignments with declared J…
Browse files Browse the repository at this point in the history
…SDoc types (microsoft#47951)
  • Loading branch information
a-tarasyuk committed Mar 1, 2022
1 parent e64f04b commit 0637148
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions tests/baselines/reference/checkJsdocTypeTagOnExportAssignment8.js
Original file line number Diff line number Diff line change
@@ -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'
};
Original file line number Diff line number Diff line change
@@ -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))
}

Original file line number Diff line number Diff line change
@@ -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"
}

17 changes: 17 additions & 0 deletions tests/cases/compiler/checkJsdocTypeTagOnExportAssignment8.ts
Original file line number Diff line number Diff line change
@@ -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'
}

0 comments on commit 0637148

Please sign in to comment.