Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Inconsistent errors when assigning to property with index signature on object vs function #26647

Copy link
Copy link

Description

TypeScript Version: 3.1.0-dev.20180823

Code

interface Idx {
    [key: string]: number;
}

interface Obj {
    idx?: Idx;
}
const l: Obj = {};
l.idx = {}; // Works

interface Fn {
    (): void;
    idx?: Idx;
}
const fn: Fn = () => {}; // Error: `{}` not assignable to `Idx`
fn.idx = {};

Expected behavior:

No error.

Actual behavior:

src/a.ts:15:7 - error TS2322: Type '{ (): void; idx: {}; }' is not assignable to type 'Fn'.
  Types of property 'idx' are incompatible.
    Type '{}' is not assignable to type 'Idx'.
      Index signature is missing in type '{}'.

Discovered in koa-morgan on DefinitelyTyped. Probably due to #26368.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptDuplicateAn existing issue was already createdAn existing issue was already created

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.