-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" insteadCanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
consider the following class.
class GenericPractice<T>{
private entity: T;
constructor(entity: T) {
this.entity = entity;
}
public add(item: T): string {
return item.toString();
}
}
class CouponInfo {
public toString(): string {
return "couponInfo";
}
}
class Snake{
}
var genericPractice = new GenericPractice<CouponInfo>(new CouponInfo());
genericPractice.add(new Snake("Sammy the Python")));
theoretically, the above last line:
genericPractice.add(new Snake("Sammy the Python")));
should have compile time error since the generic of class GenericPractice should only allow CouponInfo in method add, not Snake.
However, the compile still passes which violates the fundamental concept of generic.
is this a bug?
Metadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" insteadCanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code