cf.completefrontend

Write the codeHard

Write LiteralUnion<T>: suggest some string literals in the editor, but still accept any string.

A Size is "small", "medium", "large", or any other string, like "2xl". The obvious "small" | "medium" | "large" | string collapses to plain string, so editors stop suggesting the three sizes. Write a LiteralUnion<T> that keeps them.

Write this
type LiteralUnion<T extends string> = T | string; type Size = LiteralUnion<"small" | "medium" | "large">;// Should keep "small" | "medium" | "large" for autocomplete,// and still accept any string, like "2xl".

Solve it in the editor

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…