Skip to content

Suggestion: Allow skipping the properties of type void #15189

@emirotin

Description

@emirotin

TypeScript Version: 2.3.0

Code

I'd like this to be a valid TS:

interface T {
  a: number;
  b: void;
}

const x: T = { a: 1 }

Why would I?

This contrived example doesn't make much sense. Why would someone define a property of type void and then be willing to skip it, right?

Here's a lengthy explanation of my problem: http://stackoverflow.com/questions/43387510/typescript-for-generic-type-interface-make-the-property-required-only-if-its

Long story short I have a generic interface, whenever the type parameter is a real type I want the property to be required, so I cannot mark it as optional.
But if the type is void (and I do use 2.3.0's default type parameters feature to set it and thus make the type parameter itself optional) I don't want to keep typing b: undefined everywhere.

Impact on emitted code: none, it only touches the TS compile-time validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions