Skip to content

Type refinement on properties no longer refines the whole structureΒ #58197

Closed as not planned
@sukovanej

Description

@sukovanej

πŸ”Ž Search Terms

type guard, type refinement, typescript 5.4.3

πŸ•— Version & Regression Information

  • This changed between versions 5.4.2 and 5.4.3

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBA6lC8UDeUBOECGATA9gOwBsQpRIAuKAcg0oG4oAjCvAVwFsGJUoBfWgKFLQAWgmRpMuQsSEVKDOlADGFAM7BUASzwBzXgKFQAGmLgAfKMIH8sEJQQzpl+dVAAeFI9aUvgUTaoAgmIAFLJUNFAW8pQAlBSGARGUCAB8JODQ8NnJ1poAZlAhAYEhbgB0QrGxyPxQ7uUM9AD0ze5QABYYqlAYGZDG-njqklA4hTD8PEA

πŸ’» Code

type W = { readonly type: 'a'; b: number };
type Z = { readonly type: 'b'; c: string };
type X = W | Z;

declare const x: X;

const isA = (type: 'a' | 'b'): type is 'a' => type === 'a';

if (isA(x.type)) {
  x.b; // x has a type X instead of W
}

πŸ™ Actual behavior

the x has the wider type X

πŸ™‚ Expected behavior

x has the concrete type W

Additional information about the issue

No response

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