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

Type inference problems when using string literal types #16523

Description

TypeScript Version: 2.3.4

Code

function example(parameter: { value: "a" }) { // Function requires argument with string literal
    return;
}

var myObject = {
    value: "a" // TS infers value to be string here, causing problems passing this object to function
};

example(myObject); // Error: Argument of type '{ value: string; }' is not assignable to parameter of type 'ObjectType'. Types of property 'value' are incompatible. Type 'string' is not assignable to type '"a"'.

Expected behavior:
No compiler error

Actual behavior:
Compiler error (see self-contained example)

No activity

Activity on this issue will appear here.

Activity

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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions