X Tutup
Skip to content

New functions - interface recursion#287

Merged
Perryvw merged 22 commits intoTypeScriptToLua:new-functionsfrom
tomblind:new-functions
Nov 29, 2018
Merged

New functions - interface recursion#287
Perryvw merged 22 commits intoTypeScriptToLua:new-functionsfrom
tomblind:new-functions

Conversation

@tomblind
Copy link
Collaborator

This PR addresses the issue where assignment validation would incorrectly pass when assigning an object to an interface type where methods had mismatched context parameters:

interface A {
    method(s: string): string;
}
interface B {
    method(this: void, s: string): string;
}
declare let a: A;
let b: B = a; // Should Error

Validation now recurses into interface and class types to check the methods being assigned. To avoid an infinite loop for recursive types, a cache is used to track previous comparisons. This has the fringe benefit of improving performance in code with a lot of assignments using the same types.

Additionally, the name of the function/method is now passed to the error when it occurs in an interface assignment. This is useful for tracking down the offending member in complex interface assignments.

Copy link
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing some tests for all this stuff still

new TranspileError(`Unsupported conversion from method to function.`, node)
public static UnsupportedFunctionConversion = (node: ts.Node, name?: string) => {
if (name) {
return new TranspileError(`Unsupported conversion from method to function "${name}".`, node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this error should be something like 'Can not implicitly convert method to function, to explicitly convert, wrap function call in a lambda function.'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured this could be improved upon a lot once we've nailed things down.

@Perryvw Perryvw merged commit 441a2e8 into TypeScriptToLua:new-functions Nov 29, 2018
@tomblind
Copy link
Collaborator Author

I actually have a file with a plethora of tests I'm using to validate as I go. Once things are locked in I'll convert it to proper functional tests and commit them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup