Skip to content

tsc may fail to report error when file.js & file.d.ts coexist, even when @ts-check is added on file.js.Β #63523

@hkleungai

Description

@hkleungai

πŸ”Ž Search Terms

ts-check

πŸ•— Version & Regression Information

  • This changed between versions 4.4.4 and 4.5.2

⏯ Playground Link

Meaningless to paste playground link I guess, when it is about typechecking plain javascript file

πŸ’» Code

src/main.js

// @ts-check
export const x = parseFloat(3.14);

src/main.d.ts

export const x: number;
{
    "compilerOptions": {
        "rootDir": ".",
        "outDir": "./dist",
        "target": "esnext",
        "types": [],
        "sourceMap": true,
        "strict": true,
        "isolatedModules": true,
        "skipLibCheck": true,
        "allowJs": true,
    },
    "include": [
        "src/*.js",
        "src/*.d.ts",
    ]
}

πŸ™ Actual behavior

No error.

πŸ™‚ Expected behavior

src/main.js:3:29 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

3 export const x = parseFloat(3.14);
                              ~~~~


Found 1 error.

Additional information about the issue

Note that the error will reappear when "include" is reorder as ["src/*.d.ts", "src/*.js"].

Also note that https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html mentioned no such behaviour change regarding @ts-check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions