镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

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: { ... } });

Activity

  1. changed the title [-]TS loosing optional properties when used with index signature and generics[/-] [+]TS losing optional properties when used with index signature and generics[/+] on Jul 22, 2016
  2. modified the milestones: TypeScript 2.1, on Sep 29, 2016
  3. added a commit that references this issue on Feb 21, 2017
    26c24f0
  4. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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