Skip to content

Commit

Permalink
Merge pull request #56 from lgeiger/remove-this-parameter
Browse files Browse the repository at this point in the history
Remove this annotation in function declarations
  • Loading branch information
orta authored Oct 14, 2018
2 parents 4425490 + 1f99233 commit cc6dfe2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/__tests__/__snapshots__/function_exports.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ declare export function syncHistoryWithStore(
): History & HistoryUnsubscribe;
"
`;
exports[`should remove this annotation from functions 1`] = `
"declare function addClickListener(onclick: (e: Event) => void): void;
"
`;
7 changes: 7 additions & 0 deletions src/__tests__/function_exports.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ export function syncHistoryWithStore(history: History, store: Store<any>, option
const result = compiler.compileDefinitionString(ts);
expect(beautify(result)).toMatchSnapshot();
});

it("should remove this annotation from functions", () => {
const ts =
"function addClickListener(onclick: (this: void, e: Event) => void): void;";
const result = compiler.compileDefinitionString(ts);
expect(beautify(result)).toMatchSnapshot();
});
4 changes: 3 additions & 1 deletion src/printers/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type { RawNode } from "../nodes/node";
import printers from "./index";

export const functionType = (func: RawNode, dotAsReturn: boolean = false) => {
const params = func.parameters.map(printers.common.parameter);
const params = func.parameters
.filter(param => param.name.text !== "this")
.map(printers.common.parameter);
const generics = printers.common.generics(func.typeParameters);
const returns = func.type ? printers.node.printType(func.type) : "void";

Expand Down

0 comments on commit cc6dfe2

Please sign in to comment.