Skip to content

Irregular behavior of generic non arrow function that is typed via JSDoc import. #49039

@lillallol

Description

@lillallol

Bug Report

🔎 Search Terms

allowJs, checkJs, type imports via JSDoc, generic functions, no compile, inconsistent behavior, inline type, arrow

💻 Code

  • ./privateApi.ts
export type IFn = <T>(m : T[][]) => T[][];

const inTsArrow = <T>(m : T[][]) : T[][] => {
    return m;
}
inTsArrow([[1]]); // no error gets linted as expected

function inTs<T>(m : T[][]) : T[][] {
    return m;
}
inTs([[1]]); // no error gets linted as expected
  • ./index.js
/**@type {import("./privateApi").IFn}*/
export function inJs(m) {
    return m;
}
inJs([[1]]); // lints error. Why?

/**@type {import("./privateApi").IFn}*/
const inJsArrow = (m) => {
    return m;
}
inJsArrow([[1]]); // no error gets linted as expected
  • ./tsconfig.json
{
    "compilerOptions": {
        "checkJs": true,
        "allowJs": true,
        "target": "ESNext",
        "strict": true,
        "noEmit": true,
        "rootDir": "./",
        
        "skipDefaultLibCheck": true,
        
        "noUnusedLocals": true,
        "noUnusedParameters": true,
    },
    "include": [
        "./**/*.ts",
        "./**/*.js"
    ],
    "exclude": [
        "node_modules",
        "TBD"
    ]
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions