Skip to content

Allow non-null assertion operator on destructuringΒ #63131

@AFatNiBBa

Description

@AFatNiBBa

πŸ” Search Terms

destructuring non null assertion operator

βœ… Viability Checklist

⭐ Suggestion

Allow the non-null assertion post-fix operator to be used in destructuring assignments

πŸ“ƒ Motivating Example

I was destructuring an object with a long name, but I couldn't do so because I also needed to assert it wasn't null, and this is not currently allowed

const { veryVeryVeryLongPropertyName! } = obj;

So I had to do this

const veryVeryVeryLongPropertyName = obj.veryVeryVeryLongPropertyName!;

πŸ’» Use Cases

What do you want to use this for?

To avoid having to specify the name twice

What workarounds are you using in the meantime?

// Workaround: Short name
// Shortcoming: Not what I actually wanted to do
const temp = obj.veryVeryVeryLongPropertyName!;

// Workaround: Default `never` value
// Shortcoming: Verbose
const { veryVeryVeryLongPropertyName = undefined! } = obj;

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