Closed as not planned
Description
π Search Terms
require shadowing javascript import scope local
π Version & Regression Information
- This changed between versions 4.0.5 and 4.1.2 (since
require
module resolution was introduced in 4.1.0-dev.20200818 with Alias for commonjs require in JSΒ #39770).
β― Playground Link
π» Code
function () {
/** @param {string} name */
function require(name) { return Number(name) }
const someNumber = require('someName');
}
π Actual behavior
someNumber
is an import.- It raises a type import error:
Cannot find module 'someName' or its corresponding type declarations.
π Expected behavior
someNumber
has typenumber
.- No error is raised.
Additional information about the issue
This is only the case when using type inference with JavaScript files. With TypeScript it works as expected (playground):
function () {
function require(name: string) { return Number(name) }
const someNumber = require('someName');
}
If the type of someNumber
is explicitely written, it also works as expected (playground):
function () {
/** @param {string} name */
function require(name) { return Number(name) }
/** @type {number} */
const someNumber = require('someName');
}