Skip to content

Index signature kills property completions from constraint #22077

@jwbay

Description

@jwbay

TypeScript Version: 2.8.0-dev.20180220

Search Terms:
index signature completion
constraint completion

Code

interface Styles {
  alignContent: string | null;
  alignItems: string | null;
  alignmentBaseline: string | null;
  // etc..
  [key: string]: any
}

interface StyleMap {
  [name: string]: Partial<Styles>
}

declare function createStyles<T extends StyleMap>(styles: T): T

createStyles({
  x: {
    '/*1*/': ''
  }
});

Expected behavior:
Requesting completions at 1 shows property names from Styles.

Actual behavior:
Requesting completions at 1 shows generic words from the file.

Remove the index signature from StyleMap and the properties show up.

Playground Link:
http://www.typescriptlang.org/play/#src=interface%20Styles%20%7B%0A%20%20alignContent%3A%20string%20%7C%20null%3B%0A%20%20alignItems%3A%20string%20%7C%20null%3B%0A%20%20alignmentBaseline%3A%20string%20%7C%20null%3B%0A%20%20%2F%2F%20etc..%0A%20%20%5Bkey%3A%20string%5D%3A%20any%0A%7D%0A%0Ainterface%20StyleMap%20%7B%0A%20%20%5Bname%3A%20string%5D%3A%20Partial%3CStyles%3E%0A%7D%0A%0Adeclare%20function%20createStyles%3CT%20extends%20StyleMap%3E(styles%3A%20T)%3A%20T%0A%0AcreateStyles(%7B%0A%20%20x%3A%20%7B%0A%20%20%20%20'%2F*1*%2F'%3A%20''%0A%20%20%7D%0A%7D)%3B

Related Issues:
#9900 -- that seems to be fixed since removing the index signature fixes this even with everything else optional. Adding a required property to Styles restores completions though.

The usefulness of this is kind of predicated on #12968 as far as the quotes being required to trigger completions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Completion ListsThe issue relates to showing completion lists in an editor

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions