-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Weak type detection only works with object literals being passed #17656
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
Comments
These are the rules described in #16047. I don't remember why we allow call signatures to satisfy the weak types, but there was a reason |
Before you close it, let me add the following. const v1 : ITest = new Test(); //<-- compiler allows this
const v2 : ITest = test; //<-- compiler allows this So, it isn't just for function parameters. |
@sandersn is trying to remember why we allow types with call/construct signatures to be assigned in. We had to add it for a reason. The |
Yeah, agree about the Test() class, but the function is strange. |
Here's the test case from 548f92a // Ctor isn't a weak type because it has a construct signature
interface Ctor {
new (s: string): K
n?: number
}
let ctor: Ctor = K
// Ctor is similar to the more common type:
class C {
constructor() { }
static n?: number;
}
|
@RyanCavanaugh the question that @ownerer raises isn't whether |
There's just an ad-hoc filter |
It turns out the check needs to be positive, so I changed it to |
TypeScript Version: 2.4.0
Code
Expected behavior:
Passing any object of any type that doesn't match with at least one of the properties defined in the weak type, should fail.
Actual behavior:
Only object literals that don't at least partially match are not allowed to be passed.
The text was updated successfully, but these errors were encountered: