Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sandersn opened this issue Aug 19, 2020 · 1 comment · Fixed by #40186
Closed

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

sandersn opened this issue Aug 19, 2020 · 1 comment · Fixed by #40186
Assignees
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

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.

@sandersn sandersn self-assigned this Aug 19, 2020
@sandersn sandersn added this to the TypeScript 4.1.0 milestone Aug 19, 2020
@sandersn sandersn added the Bug A bug in TypeScript label Aug 19, 2020
@DanielRosenwasser DanielRosenwasser added checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically labels Aug 19, 2020
@sandersn
Copy link
Member Author

Accessing arbitrary properties on a class that extends an alias of an untyped module is also now disallowed, although this is the same as TS:

class K extends sh {
    constructor() {
        super()
        this.whatever() // now there's an error here, same as in TS
    }
}

@sandersn sandersn changed the title Assignment to untyped imports in JS results in error Nested assignment to untyped imports in JS results in error Aug 21, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 21, 2020
@RyanCavanaugh RyanCavanaugh added Rescheduled This issue was previously scheduled to an earlier milestone and removed Rescheduled This issue was previously scheduled to an earlier milestone labels Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants