Skip to content

TS2345 Error when using string literal types in array.map #11054

Description

@k8w

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx) 2.0.2@rc

Code

interface FolderContentItem{
    type: 'folder' | 'file';
}

let a:FolderContentItem[] = [];
a = [1,2,3,4,5].map(v=>({type:'folder'}))

Expected behavior:
Compiled successfully

Actual behavior:

test.ts(6,1): error TS2322: Type '{ type: string; }[]' is not assignable to type 'FolderContentItem[]'.
  Type '{ type: string; }' is not assignable to type 'FolderContentItem'.
    Types of property 'type' are incompatible.
      Type 'string' is not assignable to type '"folder" | "file"'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions