Skip to content

In JS, this-property type annotation is ignored when initializer is empty object literal #26427

@sandersn

Description

@sandersn

From webpack/lib/Compilation.js (but simplified):

/** @param {{ [s: string]: number }} map */
function mappy(map) {}
export class C {
    constructor() {
        /** @type {{ [assetName: string]: number}} */
        this.assets = {};
    }
    m() {
        mappy(this.assets)
    }
}

Expected behavior:

in mappy(this.assets), assets should have a string indexer.

Actual behavior:
this.assets: {}, and error {} is not assignable to { [s: string]: number] }

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions