Assert that a type is not branded
P粉323224129
P粉323224129 2023-08-18 11:51:11
0
1
513
<p>If we define a type brand, for example: </p> <pre class="brush:php;toolbar:false;">declare const nominalSymbol: unique symbol; type Nominal<T extends string, U> = U & { [nominalSymbol]: T };</pre> <p>Is there a way to define a type <code>NotNominal<U></code> that resolves to <code>U< if <code>U</code> is not a brand type /code>. </p> <pre class="brush:php;toolbar:false;">declare const nominalSymbol: unique symbol; type Nominal<T extends string, U> = U & { [nominalSymbol]: T }; type BrandedType = Nominal<'Address', string>; type a = NotNominal<string> // This should be `string` type b = NotNominal<Address> // This should be `never`</pre> <p><br /></p>
P粉323224129
P粉323224129

reply all(1)
P粉727531237
type NotNominal<U> = U extends { [nominalSymbol]: string } ? never : U
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template