Deno: `console.dir` implementation difference with Node

Created on 20 Aug 2020  路  4Comments  路  Source: denoland/deno

https://github.com/denoland/deno/pull/826#discussion_r473451844

this null treated as default to 2 is different with node:

in Node this null is treated as unlimited depth

> var o = { a: { b: { c: { d: new Date } } } };
undefined
> console.log(o)
{ a: { b: { c: [Object] } } }
> console.dir(o, { depth: null });
{
  a: { b: { c: { d: 2020-08-19T23:55:58.009Z } } }
}

I don't mean it should be exactly same as Node implementation, but better to be

working as designed

Most helpful comment

Let's see... an explicit { depth: null } violates the type definition of Deno.InspectOptions. When something violates our types, we let it be undefined behaviour at runtime (except for web APIs). That applies here, Deno.inspect(value, { depth: null }) (and by extension console.dir(value, { depth: null })) is not supported.

I think console.dir(o, { depth: Infinity }); is more expressive than null

I agree. Rather than adding null to the types to match Node, let's wontfix this.

All 4 comments

I think console.dir(o, { depth: Infinity }); is more expressive than null

CC @nayeemrmn what's your take on this one?

Let's see... an explicit { depth: null } violates the type definition of Deno.InspectOptions. When something violates our types, we let it be undefined behaviour at runtime (except for web APIs). That applies here, Deno.inspect(value, { depth: null }) (and by extension console.dir(value, { depth: null })) is not supported.

I think console.dir(o, { depth: Infinity }); is more expressive than null

I agree. Rather than adding null to the types to match Node, let's wontfix this.

I agree with @nayeemrmn, closing as won't fix.

Was this page helpful?
0 / 5 - 0 ratings