Skip to content

asserts that return type is null | Generic<T> is reported as null and lose the generic #49588

Closed
@jdeniau

Description

@jdeniau

Bug Report

🔎 Search Terms

  • asserts generic null
  • asserts array null

🕗 Version & Regression Information

  • This is the behavior in every version I tried (3.7 on the playground as asserts did appear in 3.7 IIRC), and I reviewed the FAQ for entries about null asserts

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Generic<T> { value: T; }
type Ticket = {}
type TicketGeneric = null | Generic<string | Ticket>

function assertRelationIsNullOrGenericOfString(v: Generic<string | Ticket> | null): asserts v is Generic<string> | null {}

function testGeneric(ticketGeneric: TicketGeneric) {
  assertRelationIsNullOrGenericOfString(ticketGeneric)

  ticketGeneric;  // expected type is `null | Generic<string>` but gave `null`
}

🙁 Actual behavior

When an asserter return null or a Generic, it is reported as null.
It does this for every generic, even Array<string>. If the return type is not a generic, it does work fine (with null | string for exemple)

🙂 Expected behavior

It should be marked as null | Generic<string>

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions