Skip to content

Support explicit type compatibility assertion #16605

@vilicvane

Description

@vilicvane

Sometimes we may want to explicitly assert whether the type of a expression is compatible with a certain type, but type assertion does not satisfy the type safety we want:

interface SomeEventData {
  foo: number;
  bar: string;
}

this.emit('some-event', {foo: 123} as SomeEventData);

The behavior is desired but it would be nice if we have an elegant way for more secure type checking instead of:

let data: SomeEventData = {foo: 123};

E.g.:

this.emit('some-event', {foo: 123}: SomeEventData);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions