Skip to content

TS losing optional properties when used with index signature and generics #9900

Closed
@asvetliakov

Description

@asvetliakov

TypeScript Version: 2.0.0-beta

Code

Base code:

// A *self-contained* demonstration of the problem follows...
    interface Test {
        a?: number;
        b?: string;
    }
    interface TestWithStrictProp {
        a?: number;
        b?: string;
        c: string;
    }

    interface TestIndex {
        [key: string]: Test;
    }
    interface TestIndexWithStrict {
       [key: string]: TestWithStrictProp;
    }
    declare function testFunc<T extends TestIndex>(t: T): void;
    declare function testFuncStrict<T extends TestIndexWithStrict>(t: T): void;

Consumer code

testFunc({
  test: {
      // Compiler doesn't see properties here
  }
});

testFuncStrict({
  test: {
     // Compiler see a?, b? and c
  }
});

Expected behavior:
Completion in testFunc({ test: { ... } });

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions