简体   繁体   中英

Getting Unexpected token eslint error when using Gsap's ScrollTo plugin

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? At least I want to be able to tell eslint to ignore this error.

Here is the eslint error:

在此处输入图像描述

Here is my .eslintrc :

{
  "extends": "eslint:recommended",
  "parser": "babel-eslint",
  "env": {
    "node": true,
    "es6": true,
    "browser": true
  }
}

Here is my code:

import { ScrollToPlugin } from "gsap/ScrollToPlugin";
import { gsap } from "gsap";
gsap.registerPlugin(ScrollToPlugin);

export const headerInteractionHandler = () => {
  document.querySelector("header .logo").addEventListener("click", (e) => {
    e.preventDefault();
    let element = <HTMLAnchorElement>e.currentTarget;

    gsap.to(window, {
      duration: 0.8,
      scrollTo: `${element.getAttribute("data-destination")}`,
    });
  });
};

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 update my .eslintrc like below and the problem is gone.

{
  
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM