Skip to content

improved function expression type inference #381

Merged
tomblind merged 3 commits intomasterfrom
func-exp-infer
Feb 6, 2019
Merged

improved function expression type inference #381
tomblind merged 3 commits intomasterfrom
func-exp-infer

Conversation

@tomblind
Copy link
Copy Markdown
Collaborator

@tomblind tomblind commented Feb 5, 2019

When tstl transpiles a function expression or arrow function, it attempts to infer whether it should be transpiled with a "self" parameter or not, based on what it is being assigned to.

Currently, this does not work in complex scenarios where function expressions were in array or object literals:

interface Foo {}
interface FooMethod {
    (this: Foo, s: string): string;
}
const methodArray: FooMethod[] = [s => s]; // Used to be an error
interface Foo {
    bar(this: void, s: string): string;
}
const foo: Foo = {
    bar: s => s // Used to be an error
};

This PR adds support for properly inferring the self type in these situations and prevents those annoying function/method conversion errors.

also fixes #340

Copy link
Copy Markdown
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.

Looks good. Since this fixes #340, could you also add a test for that case?

@tomblind tomblind merged commit 661d5b0 into master Feb 6, 2019
@tomblind tomblind deleted the func-exp-infer branch February 6, 2019 12:41
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.

Brackets around inline functions break the transpiler

3 participants