Basic Typescript Types Typescript is a typed superset of Javascript. For this challenge, we'll consider the following classic basic types:

string
number
boolean
undefined
null

And two &quot;meta&quot; types:

any
never

The type any annotates that any type is valid:
const a: any = &quot;foo&quot;;
const b: any = 42;
const c: any = true;
const d: any = undefined;

Whereas never annotates that no type is valid:
const e: never = &lt;no valid literal assignment possible&gt;;

We'll also consider two compositions of types: unions and intersections, annotated as | and &amp; respectively.
A union type expects either one or the other type:
const f: string | number = &quot;foo&quot;;
const g: string | number = 42;

While an intersection creates a combination of both types:
const h: string &amp; any = &quot;foo&quot;;
const i: string &amp; any = 42;
const j: string &amp; number = &lt;no valid literal assignment possible&gt;;

The order of operands within unions and intersections doesn't matter, string | number is equal to number | string.
The challenge
Given one of the above type declarations, return the resulting resolved type. The input will be one of the following:

a basic type as listed above or;
a meta type as listed above or;
a union of two basic and/or meta types or;
an intersection of two basic and/or meta types.

Examples
// All basic and meta types simply map to themselves
string → string
number → number
any → any
never → never

// Unions between basic types create unions except with themselves
string | number → string | number
string | undefined → string | undefined
string | string → string

// Intersections between basic types create never except with themselves
string &amp; number → never
string &amp; undefined → never
string &amp; string → string

// Unions with any create any
any | string → any
any | never → any

// Intersections with any result in any except with never
any &amp; string → any
any &amp; number → any
any &amp; never → never

// Unions with never yield the other half
never | string → string
never | any → any
never | never → never

// Intersections with never return never
never &amp; string → never
never &amp; any → never
never &amp; never → never

A good way to get a feel for the types is to try out the Typescript playground.
Any reasonable and consistent input-output format, standard loop holes, code-golf.
Python 3, 261 bytes

lambda x,o=&quot;&amp;&quot;,y=&quot;&quot;:(&quot;any&quot;in x+y)*(o&lt;&quot;|&quot;)*-~-(&quot;never&quot;in x+y)*&quot;any&quot;or(lambda r:r==31and&quot;any&quot;or&quot;|&quot;.join(&quot;ubsnnnotuudormleliblfene iagr nn   e    d&quot;[i::5]for i in range(5)if r&amp;2**i)or&quot;never&quot;)(eval(o.join(str(min(31,2**&quot;dormlyv&quot;.find(k[2])%64))for k in[x,y or x])))

Try it online!
-1 byet thanks to ovs