I installed @types/greensock
and started using gsap
with TypeScript
. Everything works fine, but the ScrollTo
plugin is giving this eslint
error (image attached). Someone knows something about it?
Here is the eslint error:
Here is my .eslintrc
:
JavaScript
x
10
10
1
{
2
"extends": "eslint:recommended",
3
"parser": "babel-eslint",
4
"env": {
5
"node": true,
6
"es6": true,
7
"browser": true
8
}
9
}
10
Here is my code:
JavaScript
1
16
16
1
import { ScrollToPlugin } from "gsap/ScrollToPlugin";
2
import { gsap } from "gsap";
3
gsap.registerPlugin(ScrollToPlugin);
4
5
export const headerInteractionHandler = () => {
6
document.querySelector("header .logo").addEventListener("click", (e) => {
7
e.preventDefault();
8
let element = <HTMLAnchorElement>e.currentTarget;
9
10
gsap.to(window, {
11
duration: 0.8,
12
scrollTo: `${element.getAttribute("data-destination")}`,
13
});
14
});
15
};
16
Advertisement
Answer
I have been told in the GreenSock forum that I shouldn’t be using @types/greensock
as gsap
has built in support for TypeScript. So I deleted it, and I updated my .eslintrc
by replacing babel-eslint
by @typescript-eslint/parser
like below and the problem is gone.
Needed installs:
JavaScript
1
2
1
npm i @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev
2
.eslintrc:
JavaScript
1
11
11
1
{
2
3
"parser": "@typescript-eslint/parser",
4
"plugins": ["@typescript-eslint"],
5
"extends": [
6
"eslint:recommended",
7
"plugin:@typescript-eslint/eslint-recommended",
8
"plugin:@typescript-eslint/recommended"
9
]
10
}
11