Skip to content

Docs: "Type assertion" vs "asserts" keyword #35653

@bcherny

Description

@bcherny

Hey there!

I’m updating Programming TypeScript to include assertions in control flow analysis, and was looking for guidance about naming.

Type assertions (x as T) and assertions in control flow analysis (asserts x is T) are similarly named. What’s a good way to call these these features, in a way that doesn’t confuse people and aligns with the way the TS team is communicating it?

A couple of ideas:

  1. Rename x as T to “type coercion” or “type casting" (even though it’s not a runtime behavior), and call asserts x is T a “type assertion”
  2. Keep x as T as-is (“type assertion”), and call asserts x is T a “user-defined type assertion”, similar to a “user-defined type guard”

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionIssues which may not have code impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions