Skip to content

Function return type with array #33158

@deser

Description

@deser

TypeScript Version: 3.6.2

Search Terms:
map\array\return type

Code

const fetchCustomVariables = (): { name?: string; type?: string }[] => {
    const variableList: { name?: string; type: string }[] = [];
    return variableList.map(v => ({ nasme: v.name, type: v.type }));
};

NotificationsForm 2019-08-30 13 12 07
NotificationsForm 2019-08-30 13 14 15

Expected behavior:
Typescript complaints that array of objects generated by map doesn't match function return type.

Actual behavior:
Typescript doesn't complaint that array of objects generated by map doesn't match function return type.

Playground Link:
http://www.typescriptlang.org/play/#code/PTAEGUAsHsFcBsAmoDG0C2AHeBDAlgHYBQaBAzgC6gBmAphSpAMKyUYBqOATnjgEbxaZUAF5QACgCUALlABvUARzpaAflmUeBAOYBuUBQCemNRopbtoAL4BtALqiAfPKKg3qaOSoA3brwG0ADJ4lLIKSirqoJqEegbGtGYW1vaioPa6ru5c9LBcBKC+PPyCwZQAdOg4mOLeThLhOGQqst7lEbQANPEmreVGJtaSkplWmUQgoACCwpC0OSSelDT0jCxs6JzFAWQATGlSYYrKptHmsfoDpzE61vVyWW6ky0X+pSEURx1RN3FXSbEUg4xBlHqAchQ8gVGs1EqAAOQARnh3X+CN28LGRCxQA

Related Issues:
No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions