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

Make duck-typing optional. #251

Closed
zpdDG4gta8XKpMCd opened this issue Jul 25, 2014 · 2 comments
Closed

Make duck-typing optional. #251

zpdDG4gta8XKpMCd opened this issue Jul 25, 2014 · 2 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@zpdDG4gta8XKpMCd
Copy link

I wish I could turn duck-typing off sometimes because it leads to bugs that very hard to detect.

For example:
Suppose I have 2 interfaces with the same surface but completely unrelated sematics:

interface Chicken {
   id: number;
   name: string;
}

interface JetPlane {
   id: number;
   name: string;
}

then doing the following is completely fine in TypeScript:

var chicken : Chicken = { id: 1, name: 'Thomas' };
var plane: JetPlane = { id: 2, name: 'F 35' };
chicken = plane;

I wish there was an option to prevent such assignment from being valid.

@samwgoldman
Copy link

This is a duplicate of #202.

@RyanCavanaugh
Copy link
Member

Agreed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants