dandv
dandv2w ago

Deno check/lint doesn't warn against obvious bugs

type Point = {
[key: string]: number
};

function processPoints(points: Point[]): string[] {
// Should error on Object.keys(number), TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
// Should warn on points[3] possibly being undefined
return Object.keys(points[3].foo);
}

console.log(processPoints([ { bar: 2 } ]));
type Point = {
[key: string]: number
};

function processPoints(points: Point[]): string[] {
// Should error on Object.keys(number), TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
// Should warn on points[3] possibly being undefined
return Object.keys(points[3].foo);
}

console.log(processPoints([ { bar: 2 } ]));
I've run deno lint --rules-tags=recommended but it doesn't detect anything. This is quite worrying. PS: should there be a Lint tag when posting here, now that we have lint plugins?
6 Replies
marvinh.
marvinh.2w ago
You might be looking for deno check instead. At the moment deno lint does no type checking whereas deno check does. In either way there wouldn't be a type error in the code posted. Calling Object.keys() on a number always yields an empty array and an empty array is a valid string[]
dandv
dandvOP7d ago
@marvinh. deno check was my first line of defense, but it doesn't output anything about this code. tsc does:
$ cat warnme.ts
type Point = {
[key: string]: number
};

function processPoints(points: Point[]): string[] {
// Should error on Object.keys(number), TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
// Should warn on points[3] possibly being undefined
return Object.keys(points[3].foo);
}

console.log(processPoints([ { bar: 2 } ]));

$ deno check warnme.ts

$ tsc warnme.ts
warnme.ts:8:22 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.

8 return Object.keys(points[3].foo);
~~~~~~~~~~~~~


Found 1 error in warnme.ts:8
$ cat warnme.ts
type Point = {
[key: string]: number
};

function processPoints(points: Point[]): string[] {
// Should error on Object.keys(number), TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
// Should warn on points[3] possibly being undefined
return Object.keys(points[3].foo);
}

console.log(processPoints([ { bar: 2 } ]));

$ deno check warnme.ts

$ tsc warnme.ts
warnme.ts:8:22 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.

8 return Object.keys(points[3].foo);
~~~~~~~~~~~~~


Found 1 error in warnme.ts:8
marvinh.
marvinh.7d ago
I see, that sounds like a bug. Can you file an issue for that at https://github.com/denoland/deno/issues ?
CodyC
CodyC4d ago
It looks like Object.keys() is overloaded: Did an issue get opened for this? I can add this there if so.
No description
CodyC
CodyC4d ago
GitHub
deno check != tsc w.r.t. Object.keys() · Issue #28433 · denol...
Version: deno 2.2.3+0ef3f6b (canary, release, x86_64-pc-windows-msvc) v8 13.4.114.11-rusty typescript 5.7.3 Originally reported on Discord type Point = { [key: string]: number }; function processPo...
CodyC
CodyC4d ago
As for:
// Should warn on points[3] possibly being undefined
Unfortunately, even typescript "strict" mode doesn't enable this check. There is a LOT of code that just assumes your indexes are in-bounds. It can become tedious to check undefined for all cases. If you want that check, you have to enable: https://www.typescriptlang.org/tsconfig/#noUncheckedIndexedAccess

Did you find this page helpful?