Skip to content

Type inference for exact strings #16276

Closed
@ajcrites

Description

@ajcrites

TypeScript Version: 2.2.2

Code

interface Css {
  position: 'absolute' | 'relative';
}
function style(rules: Css) { }

const rules = { position: 'absolute' };
style(rules);
style({ position: 'absolute' });

Expected behavior:
There should be no type issues.

Actual behavior:
style(rules) yields

Argument of type '{ position: string; }' is not assignable to parameter of type 'Css'
Types of property 'position' are incompatible

Using style({position: 'absolute'}) works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn 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