Skip to content

Make duck-typing optional. #251

Closed
Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions