Type inference for exact strings · Issue #16276 · microsoft/TypeScript (original) (raw)

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.