Conversation
…gning to untyped vars
|
Wow you've been busy, sounds very good! I'll have a look at this later today or tomorrow. |
|
No problem - whenever you have time. It's definitely not ready for integration but worth taking a look at. One more edge case I forgot to mention: interface F {
(this: Foo, s: string): string;
(s: string): string;
}
let fn: F = foo.method; // ErrorOverloads that have both methods and non-methods are currently treated as non-methods when doing the assignment checks. We might want to change things to allow either in this situation. |
| } else if ((fromType as ts.TypeReference).typeArguments && (toType as ts.TypeReference).typeArguments) { | ||
| // Recurse into tuples/arrays | ||
| (toType as ts.TypeReference).typeArguments.forEach((t, i) => { | ||
| this.validateAssignment(node, (fromType as ts.TypeReference).typeArguments[i], t); |
There was a problem hiding this comment.
🤔 Would it be possible toType.typeArguments is shorter/longer than fromType.typeArguments?
There was a problem hiding this comment.
It's definitely possible for fromType to have more than toType (destructuring, but not catching everything in the tuple), but I haven't come up with a situation where toType could have more.
| public functionBind(): void { | ||
| const source = `const abc = function (a: string, b: string) { return this.a + a + b; } | ||
| const source = `const abc = function (this: { a: number }, a: string, b: string) { return this.a + a + b; } | ||
| return abc.bind({ a: 4 }, "b")("c");`; |
There was a problem hiding this comment.
This test looks strange actually, should this not be abc.bind({a: 4})("b", "c")?
There was a problem hiding this comment.
bind() actually allows you to bind initial arguments as well. This is testing that functionality.
|
You should probably remove your |
|
Whoops! I'll dig around and make sure there's no others still floating about too. |
This PR brings everything up to what is spec'd out here: #250 (comment)
A few notes:
Current edge cases:
Right now, Func is detected as having context when it shouldn't. I need to figure out how to resolve the generic parameter when checking assignments.
Assigning to interfaces allows the check to be bypassed and calling the method on 'b' will incorrectly use the dot syntax. This should be solvable by recursively checking assignments to interface types, but this is complex and will likely add quite a lot of overhead. Need to think on this one...