⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Nested Branded type does not errorΒ #62976

@nitzcard

Description

@nitzcard

πŸ”Ž Search Terms

It may be a bug or a feature, I am not sure.
I used the branded type technique and expected it to guard it from similar nested types, but got no error.

πŸ•— Version & Regression Information

all the versions (also in 7)

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEYD2A7AzgF3gfWwIxihWAC54BXFASwEdyE0BPAWzyQgG4AoEADwAckMLBkb8EAIULEQwADwAVADTwJ8PhhDE08TDCooA5gD54AXngL4AMngBveHCjBUERvADauAkWABdMjUAX24uUXF4AEF+fggECylfWTk9A0MVAHJo2JAM425whAB5aUN41WlQeVSjTJKiMryCsQRI83gAJXAheWy4lS7kGHl6oxAVDBh6Y3ywltV2wZ65UbKB7uG5PvH4SenZrmR0LCgyNos7EK4uADNKMAwqVHgbpCQACgN+cgxAgEp7Fx4I4QBhyDAUNwgtdXh8oH9QlwgA

πŸ’» Code

declare const __brand: unique symbol;
export type Branded<T, B extends string> = T & { readonly [__brand]: B };

type Apple = Branded<string, 'Apple'>;
type Orange = Branded<string, 'Orange'>;
type A = Record<Apple, Record<Orange, true>>;
type B = Record<Orange, Record<Apple, true>>;

const a: A = {};

function foo(input: B) {
  return;
}

// Sould error
foo(a);

Note:

  • It works for an array
  • It also doesn't work for simpler, non-nested records for example Record<Apple, number>.

πŸ™ Actual behavior

foo(a) passes

πŸ™‚ Expected behavior

foo(a) should error

Additional information about the issue

No response

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