microsoft / microsoft/TypeScript

BUG: TS2488 whenever `.js` file is renamed to `.ts`

Ouverte
#44,467 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Needs Investigation
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

Description

Bug Report

Sometimes when I try to rename a .jsx or .js file to .ts or .tsx I get a really frustrating error in my typescript compilation.

TypeScript error in undefined(undefined,undefined):
Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.  TS2488

I took a long time to figure out that the renaming of the files was the issue. I had this going on for a few times and had to rollback to my latest working commit and merge file by file only to figure out that everything works and the code was exactly the same as the broken code. I have no idea why this happens and starting to suspect it is a bug with typescript.

Today it happened again with a simple react component rename. this was the component before typescript migration.
If I rename it back to .js or .jsx it works just fine. I've tried to change the filename entirely (not just the extension) and it still does not work.

/* eslint-disable require-jsdoc */
import React from 'react';
import classes from './TableFooter.module.css';
import ButtonPaginateNext from '../Buttons/Pagination/ButtonPaginateNext';
import ButtonPaginateEnd from '../Buttons/Pagination/ButtonPaginateEnd';
import ButtonPaginateBeginning from '../Buttons/Pagination/ButtonPaginateBeginning';
import ButtonPaginatePrevious from '../Buttons/Pagination/ButtonPaginatePrevious';

const TableFooter = ({
  pageNo,
  page,
  handleNext,
  handleBeginning,
  handlePrevious,
  handleEnd,
}) => (
  <div className={classes.FlexWrapper}>
    <div className={classes.FlexItem}>
      {`${page} de ${pageNo}`}
    </div>
    <div className={classes.BtnWrapper}>
      <div className={classes.FlexItem}>
        <ButtonPaginateBeginning />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginatePrevious />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginateNext />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginateEnd />
      </div>
    </div>
  </div>
);

export default TableFooter;

I made some small changes and got to this:

/* eslint-disable require-jsdoc */
import React from 'react';
import classes from './TableFooter.module.css';
import ButtonPaginateNext from '../Buttons/Pagination/ButtonPaginateNext';
import ButtonPaginateEnd from '../Buttons/Pagination/ButtonPaginateEnd';
import ButtonPaginateBeginning from '../Buttons/Pagination/ButtonPaginateBeginning';
import ButtonPaginatePrevious from '../Buttons/Pagination/ButtonPaginatePrevious';

export interface ITableFooterProps {
  pageNo: number,
  page: number,
  handleNext: () => void,
  handleBeginning: () => void,
  handlePrevious: () => void,
  handleEnd: () => void,
}

const TableFooter: React.FC<Partial<ITableFooterProps>> = ({
  pageNo,
  page,
  handleNext,
  handleBeginning,
  handlePrevious,
  handleEnd,
}) => (
  <div className={classes.FlexWrapper}>
    <div className={classes.FlexItem}>
      {`${page} de ${pageNo}`}
    </div>
    <div className={classes.BtnWrapper}>
      <div className={classes.FlexItem}>
        <ButtonPaginateBeginning />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginatePrevious />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginateNext />
      </div>
      <div className={classes.FlexItem}>
        <ButtonPaginateEnd />
      </div>
    </div>
  </div>
);

export default TableFooter;

After this, everything was working fine even if this typescript compliant code was left as a .jsx file. But if I change it to a .tsx file. It break with that horrible untracable error. What might be the problem.

I'm using the default tsconfig.json provided by create-react-app: ^17.0.2.

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "plugins": [
      {
        "name": "typescript-plugin-css-modules"
      }
    ],
    "resolveJsonModule": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "../backend",
    "../backend/**",
    "./src/ZExclude"
  ]
}

My TS version is 4.1.2

The docs say that only extension rename should work. here

UPDATE


After I create a new file (.ts) with a different filename and copy all the contents of the file (.js) I cannot delete the old .js file. Even if it is not imported in any other file. If I delete this .js file I get the same frustrating error. I´ve tried to re-install typescript and updated to version 4.3.2. Still getting the same error.

🔎 Search Terms

Type 'never' must have a 'Symbol.iterator' method that returns an iterator. ,
TS2488,
JS migration,
rename js file,

🕗 Version & Regression Information

TS 4.1.2

  • This is a crash

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le composant TableFooter et tsconfig.json fournis, puis reproduisez le renommage de .js/.jsx en .ts/.tsx avec TypeScript 4.1.2 et 4.3.2. Le travail est terminé lorsqu’une reproduction minimale du diagnostic ou du plantage TS2488 a été isolée et que le comportement a été documenté dans un test de régression.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
react, typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.