How do you type a GeoJSON Coordinate tuple and LineString array?
Tests fixed-length tuple typing versus flexible arrays in TypeScript. A strong answer uses [number, number] for Coordinate, then Coordinate[] for LineString, and explains why number[] loses length safety. Red flag: using number[] or objects instead of tuples.
Tests your grasp of TypeScript tuple types for fixed-length, positionally-semantic data like GeoJSON coordinates. A great answer defines type Coordinate = [number, number]; then type LineString = Coordinate[]; and contrasts this with number[], which accepts any length and erases the longitude-latitude positional contract. Mentioning readonly or branded types for extra safety is a bonus. Red flag: using interface Coordinate { lon: number; lat: number } or number[][] because that misses the tuple constraint the API guarantees.
Read the original → typescriptlang.org
- #typescript
- #tuples
- #geojson
- #type-systems
- #api-typing
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.