Repository: TypeScript
Issue: Irregular behavior of equivalent code between `.js` and `.ts`.
Labels: Bug,Help Wanted

# Bug Report

### 🔎 Search Terms

JSDoc import, no compile, generic function, checkJs, allowJs, inconsistent behavior

### 🕗 Version & Regression Information

typescript 4.9.4 both in vscode and in node modules

### ⏯ Playground Link & 💻 Code

full `.ts` playground [link](https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAYwgOwM7wLbAxAlgL2DgC44BJAWWz0LgF44AKAM2QEp6A+OAbwCg4guAHphcVBCxwsOAgEMYuFHAA2EAOa4EAoVGAwArlGRMAdOblR1qDnW78hjkWIlSce6dXmLlazdqddfSMTVkZzU0trNh1BAF8+OIBuOD4+UThkCHgVXGRFZHU4YCgoaDgACxLgABo4PMQUGCg5dDgYCDgAdwqFSrkwMGA0epMAA1MAK1QxvlBIWEa0eFYScgAxEwZPWUJGRiibLl5YuD1DYzgAbQBdJMS2e-ThGABPIdQ+N6HyKl2iBgAHlOAAViiAYMMACaocgAZRKuDkuXwcgARipgAA1ZEGYC3GqnABKfE4jFOq1IjDgETAljkWEhUFhpBBtm4JPZTBp5jpLUZJRZcDZxyJT2+RDICKgSJR6MxOJUeKcDCliOR8gxwCJwGY1WQCCIAB94eq5VqQTKMLhFAA3YD3CWmmUa1FanV6vQGgHO2WahW4-E3OAmnhXEBrdAywrB0hql3mgNK4DJL7vSXSv1uzGW3DWu0+qN5IomtEQCCYuQmE3IAwYNElEOZAwqFTi9MbLZMQ6kBxCKIARlIRcK9ziXNr9ZKt1uSSAA)

The equivalent code with JSDoc type imports, i.e.:

* `./index.js`

```js
/**@type {import("./types").IMemoize}*/
const memoize = (fn) => {
    // some memoization logic
    return (...args) => {
        // some more memoization logic
        return fn(...args)
    }
}; 

/**@type {import("./types").IFn}*/
const fn  =  memoize((args) => {
    return [];
});
```

* `./types.ts`

```ts
export type IMemoize = <
    P extends ISerializableValue[],
    R
>(
    fn : ( ...parameters : P) => R
) => ( ...parameters : P) => R;

type ISerializableValue     = ISerializableReference | ISerializablePrimitive;
type ISerializableReference = ISerializableValue[] | {[x : string] : ISerializableValue};
type ISerializablePrimitive = string | boolean | number | null;

export type IFn = (args: {
    arg1: string;
}) => number[][];
```

* `./tsconfig.json`

```json
{
    "compilerOptions": {
        "checkJs": true,
        "allowJs": true,
        "noEmit": true,
        "target": "ESNext",
        "module": "ESNext",
        
        "strict": true,
        
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "moduleResolution": "Node",
        "allowSyntheticDefaultImports": true
    },
    "include": [
        "./**/*.ts",
        "./**/*.js"
    ],
    "exclude": [
        "node_modules",
    ]
}
```
### 🙁 Actual behavior

Getting a linting error on `fn` on `index.js` :

```txt
Argument of type '(args: { arg1: string; }) => never[]' is not assignable to parameter of type '(...parameters: ISerializableValue[]) => never[]'.
  Types of parameters 'args' and 'parameters' are incompatible.
    Type 'ISerializableValue' is not assignable to type '{ arg1: string; }'.
      Type 'null' is not assignable to type '{ arg1: string; }'.ts(2345)
```

while not in the `fn` of the playground link.

### 🙂 Expected behavior

We are dealing with exactly the same concretions and abstractions for both cases:

1. both abstractions and concretions are written in `.ts`
1. only abstractions are written in `.ts` and only concretions are written in `.js`. Types are imported in `.js` from `.ts` via JSDoc imports.

There should not be any difference in the type checking.