From aa308b3e4d8cff3f0878f6d261aeff93a5e07649 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Yadav <79906609+sunilyadav840@users.noreply.github.com> Date: Fri, 7 May 2021 20:55:19 +0530 Subject: [PATCH] Enable TypeScript `noImplicitThis` (#761) --- .../GraphExplorerComponent/D3ForceGraph.ts | 7 +++--- tsconfig.json | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts b/src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts index 393e92b84..05825bf98 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts +++ b/src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts @@ -733,15 +733,16 @@ export class D3ForceGraph implements GraphRenderer { .attr("aria-label", (d: D3Node) => { return this.retrieveNodeCaption(d); }) - .on("dblclick", function (_: MouseEvent, d: D3Node) { + .on("dblclick", function (this: Element, _: MouseEvent, d: D3Node) { + // https://stackoverflow.com/a/41945742 ('this' implicitly has type 'any' because it does not have a type annotation) // this is the element self.onNodeClicked(this.parentNode, d); }) - .on("click", function (_: MouseEvent, d: D3Node) { + .on("click", function (this: Element, _: MouseEvent, d: D3Node) { // this is the element self.onNodeClicked(this.parentNode, d); }) - .on("keypress", function (event: KeyboardEvent, d: D3Node) { + .on("keypress", function (this: Element, event: KeyboardEvent, d: D3Node) { if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) { event.stopPropagation(); // this is the element diff --git a/tsconfig.json b/tsconfig.json index a21625007..29814265e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "allowJs": true, "sourceMap": false, "noImplicitAny": true, + "noImplicitThis": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "allowUnreachableCode": false, @@ -14,13 +15,24 @@ "target": "es2017", "experimentalDecorators": true, "emitDecoratorMetadata": true, - "lib": ["es5", "es6", "dom"], + "lib": [ + "es5", + "es6", + "dom" + ], "jsx": "react", "moduleResolution": "node", "resolveJsonModule": true, "noEmit": true, - "types": ["jest"] + "types": [ + "jest" + ] }, - "include": ["./src/**/*", "./utils/**/*"], - "exclude": ["./src/**/__mocks__/**/*"] -} + "include": [ + "./src/**/*", + "./utils/**/*" + ], + "exclude": [ + "./src/**/__mocks__/**/*" + ] +} \ No newline at end of file