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

Type inference for exact strings #16276

Description

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.

Activity

  1. KiaraGrouwstra commented on Jun 9, 2017

    @KiaraGrouwstra
    Contributor

    #16360 just now seemed a bit similar (about tuples instead of objects).

  2. mhegazy commented on Aug 26, 2017

    @mhegazy
    Contributor

    duplicate of #16523 and #12955

  3. mhegazy commented on Sep 11, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  4. locked and limited conversation to collaborators on Jun 14, 2018
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

    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