TypeScript Conditional Types Explained: The Complete Guide
You write a type alias meant to wrap anything in an array: type ToArray = T extends any ? T[] : never. Feed it string, you get string[]. Feed it string | number, you reasonably expect (string | number)[]. What you actually get is string[] | number[] — a union of two separate array types, not a single array of the union. The alias is correct. TypeScript is correct. You've just run into distribution, one of the specific, learnable rules behind conditional types — the mechanism TypeScript uses to…
Publicado no Notice. Categoria: Programação.
Leia também
Notícias sobre o mesmo assunto em outras fontes
- ProgramaçãoDev.to
TypeScript Email Fixtures Need a Lease
- ProgramaçãoDev.to
nginx2root Explained and the nginx Versions That Fix It
EsportesBBC SportChelsea's 'most complete' performance of season - Alonso
- ProgramaçãoDev.to
Find the Busiest Five Minutes With a Sliding Window in Go
