-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Generic bounds not enforced on generic argument #32330
Labels
Breaking Change
Would introduce errors in existing code
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Comments
Perhaps a simpler expression of this is function user<T>(t: T) {
let o: {} = t;
} Which I also expect should fail. |
Is an old special assignability rule case left over from when the default for an unconstrained type parameter was if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
// A type variable with no constraint is not related to the non-primitive object type.
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
errorInfo = saveErrorInfo;
return result;
}
} in |
RyanCavanaugh
added
the
Needs Investigation
This issue needs a team member to investigate its status.
label
Jul 12, 2019
weswigham
added
Bug
A bug in TypeScript
and removed
Needs Investigation
This issue needs a team member to investigate its status.
labels
Sep 24, 2019
weswigham
added
Breaking Change
Would introduce errors in existing code
Fix Available
A PR has been opened for this issue
labels
Feb 6, 2020
RyanCavanaugh
added
the
Rescheduled
This issue was previously scheduled to an earlier milestone
label
Aug 31, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Breaking Change
Would introduce errors in existing code
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
TypeScript Version: [email protected], 3.5.1
Search Terms: generic bounds toString
Code
Expected behavior:
You should not be able to pass an arbitrary T into a function that demands
T extends {}
.Actual behavior:
Despite
.toString()
being disallowed both in user() and in f1(), you can just pass it to f2() and still calltoString
on the same value.Playground Link:
http://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABMAjAHgCoD4AUcBciGAlIgN4BQiicAdFHAMpQBOMYA5jsQNwUC+FCqEiwEyAEyZEAUwAeUGWAAmAZ3L9cBIqUrU6DZm07c+g4eGjwkIVTJaZcUQiXJVkKHFF7vgErz7UUPRMrOxcPuZAA
Related Issues:
The text was updated successfully, but these errors were encountered: