Assert that a type is not branded
P粉323224129
2023-08-18 11:51:11
<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>