Skip to content

Nested assignment to untyped imports in JS results in error #40140

Closed
@sandersn

Description

@sandersn

Since the "JS require is alias" PR went in, in JS:

Prerequisite: install shelljs but NOT @types/shelljs.

const sh = require('shelljs') // no types, so `sh` is implicitly any
sh.config.fatal = true        // assignment is interpreted as assignment declaration
sh.exec('npm pack')           // `sh` is no longer properly `any`, so error that `exec` is not found.

Expected behavior:

No error, like typescript:

import sh = require('shelljs')
sh.config.fatal = true // ok, whatever, it's any
sh.exec('npm pack') // still any!

Actual behavior:

Property exec doesn't exist on type typeof shell.

Workaround:

Install @types/shelljs.

The best probable fix is to disable assignment declarations to JS aliases. It doesn't make sense to me. However, this might not happen enough to be worth fixing.

Metadata

Metadata

Assignees

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