Skip to content

Default to single literal type whenever value is omitted #20500

Closed
@agyemanjp

Description

@agyemanjp

Consider the interface:

interface xyz {
  num: 1
  str: "ok"
}

Currently the following snippet generates a type error:
let foo: xyz = {}

My proposal is the whenever a variable is declared to contain only one possible value, that value should be assumed whenever the variable's value is not specified. So, the above snippet would then not generate an error, but this would:
let foo: xyz = { num: 2 }

This proposed feature will make it easier to write clearer and simpler TypeScript code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions