microsoft / microsoft/TypeScript

JS Typedef merged with default export alias behaves strangely

Open
#32,366 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JavaScript Needs Human Review
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

in a TS file:

import Def from "./file.js"

type Q = Def;

console.log(Def);

with file.js:

const x = 12;
export {x as default};
/**
 * @typedef {string | number} default
 */

with checkJs and allowJs both on, the hover text for Def is surprisingly correct:
image

however the console.log is marked as an error, stating:

'Def' only refers to a type, but is being used as a value here.

Expected behavior:
Since the quickinfo shows it's clearly a value (and a value is, in fact, exported), the default import should be usable as a value.

Actual behavior:
The default import is not usable as a value without error.

cc @sandersn

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the TypeScript 3.4.0-dev setup using the provided .ts and .js snippets, with checkJs and allowJs enabled. Trace how the default export alias and JSDoc typedef named default are merged, then verify that the imported Def is accepted in console.log while retaining the shown type information.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.