Skip to content

Optional object literal typing #1912

Closed
Closed
@NN---

Description

@NN---

Currently it is not possible to set a type for a key in the object literal.

interface A {
    x: number;
    y: string;
}

var a = {
    // I would assume the following syntax
    // <A>q: { ... }
    q: {
        x: 1,
        y: "a"
    }
}

However it is possible to cast a literal value but it is not the same.

interface A {
    x: number;
    y: string;
}

var a = {
    // q has type 'A', and we can write anything that compatible to that literal.
    q: <A>{
        x: 1,
        y: "a"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions