How would you use const assertions in a practical UI map?
PICTURE THIS: ARRAY IN MEMORY
Index starts at 0. Scan once for max — O(n).
Simple meaning
As const on a route name array makes a union of literal strings instead of string.
WHY — TypeScript instead of guessing?
Why interviewers care about TypeScript:
question about TypeScript.
trade-offs, and what you would actually do on a Frontend project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens with tokens?
Before the model can read a sentence, it goes through these steps:
- 1As const on a
route name array makes a union of literal strings instead of string.
- 2I then type a
Record of those keys to components so a missing page is a compile error.
- 3Satisfies checks the shape
without widening, which is handy for theme token objects.
- 4Context mix
Attention looks at nearby tokens together.
- 5Next token
The model scores what should come next.
- 6Decode
IDs turn back into readable text.
EXAMPLE — See it in action
Let's see how a real sentence is tokenized (tokens may vary by model):
Note: Actual tokens and IDs depend on the tokenizer (e.g., GPT, Llama, etc.).
Key takeaway
As const on a route name array makes a union of literal strings instead of string. I then type a Record of those keys to components so a missing page is a compile error.