Skip to content

Do not rename all *.js files to *.ts after running vue add @vue/typescript - give users a choice to enable allowJs:true mode. #2676

@wujekbogdan

Description

@wujekbogdan

What problem does this feature solve?

This feature makes the JS -> TypeScript migration easier

What does the proposed API look like?

At the moment when we run @vue/typescript then vue CLI adds all required dependencies and creates all required configuration files - this is fine. But it also renames all *.js files to *.ts. IMO it doesn't help with anything. Such an automation only makes sense if we have a fresh Vue project, but if we already have an existing application, then it doesn't make the migration any easier. It's very unlikely that existing files will compile successfully. Missing types and different import syntax will cause lots of compilation failures.

So I suggest that after the vue add @vue/typescript command is executed:

  • the CLI should as whether to rename all the *.js files to *.ts
  • the CLI should ask whether to enable the allowJs: true mode.
  • the only file that should be renamed is the main.js file.

allowJs: true is the best way to migrate a JS project to TypeScript progressively. Thanks to this we can still use existing JS modules as they are, write new modules in TypeScript, and migrate existing ones one by one.

It's not my personal opinion. Setting allowJs to true is recommended in the official Migration from Javascrtipt guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions