Skip to content

const x = require("m") should create an alias symbol #25533

Description

TypeScript Version: 3.0.0-dev.20180707

Code

/// <reference path='fourslash.ts'/>

// @allowJs: true

// @Filename: /a.js
////function [|{| "isWriteAccess": true, "isDefinition": true |}x|]() {};
////module.exports = [|x|];

// @Filename: /b.js
////const [|x|] = require("./a");
////[|x|];

const [r0, r1, r2, r3] = test.ranges();
verify.referenceGroups(r2, [/*todo*/]);

Expected behavior:

x in const x is an alias of the x in function x() {}, so all references are found.

Actual behavior:

x is a variable that happens to be the same type as the other x. Only references in b.js are found.

Activity

  1. ghost added
    BugA bug in TypeScript
    on Jul 9, 2018
  2. ghost added on Jul 9, 2018
  3. ghost added
    checkJsRelates to checking JavaScript using TypeScript
    on Jul 9, 2018
  4. ghost removed this from the TypeScript 3.0.1 milestone on Jul 10, 2018
  5. ghost added this to the TypeScript 3.1 milestone on Jul 10, 2018
  6. sandersn commented on Jul 16, 2018

    @sandersn
    Member

    The in-file type of commonjs modules is usually wrong, so I'll have to fix bugs related to that before aliasing will really make sense. I will look at #25621 first.

  7. ghost reopened this on Jul 20, 2018
  8. sandersn commented on Jul 20, 2018

    @sandersn
    Member

    Turns out github didn't recognise that the "fix #xxxx" syntax occurred in a conditional clause and unconditionally closed this issue. :) Thanks for re-opening.

  9. 3 remaining items

  10. Jessidhia commented on Jan 17, 2019

    @Jessidhia

    That's only correct if the module.exports is never reassigned...... but that's the best we can do in ES modules. That is also a limitation of node's --experimentalModules.

  11. sandersn commented on Mar 13, 2019

    @sandersn
    Member

    Note that the type of module.exports inside a module is now correctly checked, which unblocks fixing this issue.

  12. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyFix AvailableA PR has been opened for this issuecheckJsRelates to checking JavaScript using TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions