denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.26k stars 5.41k forks source link

triple-slash directive fails to type check with `checkJs` enabled #21639

Open scarf005 opened 11 months ago

scarf005 commented 11 months ago

Version: Deno 1.39.0+d51fda9 (canary, x86_64-unknown-linux-gnu)

Minimal Reproduction

add.js

/// <reference types="./add.d.ts" />
export const add = (a) => a + 1

add.d.ts

export declare const add: (a: number) => number

use.ts

import { add } from "./add.js"

deno.jsonc

{
  "compilerOptions": { "checkJs": true }
}

Expected behavior

both CLI and LSP type checks add.js and use.ts according to https://docs.deno.com/runtime/manual/advanced/typescript/types#using-the-triple-slash-reference-directive

Actual behavior

$ deno check use.ts     
Check file:///home/scarf/repo/deno/cjk_slug/use.ts
error: TS7006 [ERROR]: Parameter 'a' implicitly has an 'any' type.
export const add = (a) => a + 1
                    ^
    at file:///home/scarf/repo/deno/cjk_slug/add.js:2:21

$ deno check add.js                                                                                                                                                                     Check file:///home/scarf/repo/deno/cjk_slug/add.js
error: TS7006 [ERROR]: Parameter 'a' implicitly has an 'any' type.
export const add = (a) => a + 1

both fails to type check.

nayeemrmn commented 11 months ago

Huh, I think declaration links should override any type analysis of JS files, checkJs or not.