Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type compatibility example incorrect #611

Open
lauripiisang opened this issue Oct 7, 2020 · 1 comment
Open

Type compatibility example incorrect #611

lauripiisang opened this issue Oct 7, 2020 · 1 comment

Comments

@lauripiisang
Copy link
Contributor

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:

/** 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 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.

@blakeembrey
Copy link
Collaborator

It's fixed if you have the strictFunctionTypes flag enabled (or strict) in tsconfig.json - may be worth making a PR to note this behavior has been patched behind a flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants