basarat / basarat/typescript-book
Type compatibility example incorrect
- Dominant language
- TypeScript
- Stars
- 21.6k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
The example in https://basarat.gitbook.io/typescript/type-system/type-compatibility#types-of-arguments
> This can be confusing for people coming from other languages who would expect the following to error but will not in TypeScript:
```ts
/** Type Hierarchy */
interface Point2D { x: number; y: number; }
interface Point3D { x: number; y: number; z: number; }
/** Two sample functions */
let iTakePoint2D = (point: Point2D) => { /* do something */ }
let iTakePoint3D = (point: Point3D) => { /* do something */ }
iTakePoint3D = iTakePoint2D; // Okay : Reasonable
iTakePoint2D = iTakePoint3D; // Okay : WHAT
```
[will actually error when tried out in https://www.typescriptlang.org/play][1] so I don't understand what that example is about. Tried with 3.3.3, 3.9.2, 4.0.2 . Possibly it worked in a previous ts version.
[1]: https://www.typescriptlang.org/play?#code/PQKhAIBUE8AcFNwAkCW8BOBDdBjAFtOCMALABQKAdgC4YBmmOiACgPZXUBMAIuAN7gAHgC5wlAK4BbAEYYA3OGiiJM+eAC+5DvUYt2NAMy8BIsVNnoFSs6svgAXsvNrNZcqAiQA7q3ABnTElYABtEOnFKHGoUVko-IlIyUOpwFEhMAGt4Ng4ecABecAAKWH1qURyaHgBKAoA+fnBQcAATXz9WSXhqPCoAcwSNcmTU9KzK6iMC4tKOCrKjWvyGgWa2-07u3soB4iG3CjHshd5CtMzj3O4FYGBwAHkMzEJRACV4TA7KTGlQrSOJnkzgCTjc7o9nuBRAB1JAAQUgQA
Contributor guide
Research direction
Start with the Type Compatibility section at the linked GitBook URL and reproduce the example in the linked TypeScript Playground. Check the documented assignment behavior against the cited TypeScript versions, then update the example or explanation so it matches the compiler and verify the corrected snippet in the Playground.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100