Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std/node/util/inspect: TS2345 [ERROR]: Is not assignable to parameter of type 'InspectOptions'. #7099

Closed
balupton opened this issue Aug 18, 2020 · 3 comments · May be fixed by replit/polygott#161

Comments

@balupton
Copy link
Contributor

balupton commented Aug 18, 2020

error

https://repl.it/@balupton/util-inspect#index.ts

import { inspect } from "https://deno.land/std@0.65.0/node/util.ts";

console.log(
	inspect(
		{ value: Math.random() },
		{
			showHidden: false,
			depth: 10,
			colors: true,
		}
	)
);
 deno run --lock=lock.json --lock-write --allow-all index.ts
Compile file:///home/runner/util-inspect/index.ts
error: TS2345 [ERROR]: Argument of type '{ depth: any; iterableLimit: any; compact: boolean; sorted: boolean; }' is not assignable to parameter of type 'InspectOptions'.
  Object literal may only specify known properties, and 'iterableLimit' does not exist in type 'InspectOptions'.
    iterableLimit: opts.iterableLimit ?? 100,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/std@0.65.0/node/util.ts:11:5
exit status 1
 

debugging

Unknown why this happening though, as here are the relevant sources:

deno/std/node/util.ts

Lines 7 to 15 in 9f1dcc1

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function inspect(object: unknown, ...opts: any): string {
return Deno.inspect(object, {
depth: opts.depth ?? 4,
iterableLimit: opts.iterableLimit ?? 100,
compact: !!(opts.compact ?? true),
sorted: !!(opts.sorted ?? false),
});
}

deno/cli/dts/lib.deno.ns.d.ts

Lines 1943 to 1955 in 9f1dcc1

export interface InspectOptions {
/** Traversal depth for nested objects. Defaults to 4. */
depth?: number;
/** Sort Object, Set and Map entries by key. Defaults to false. */
sorted?: boolean;
/** Add a trailing comma for multiline collections. Defaults to false. */
trailingComma?: boolean;
/** Try to fit more than one entry of a collection on the same line.
* Defaults to true. */
compact?: boolean;
/** The maximum number of iterable entries to print. Defaults to 100. */
iterableLimit?: number;
}

My only guess is that opts: any is done, which should be opts: InspectOptions however, I am unsure how that file can import InspectOptions, or even if that is the correct solution.

/ref #6833

@balupton
Copy link
Contributor Author

That said, this could be an issue on repl.it as it is running an older version of node:

 deno --version
deno 1.1.0
v8 8.4.300
typescript 3.9.2

And those fields were only added to InspectOptions in deno v1.2.0

https://github.com/denoland/deno/blob/b38c3132768e0f5132763db9c8fdc2a4a9490bde/Releases.md#120--20200713

feat(cli/js): Add sorted, trailingComma, compact and iterableLimit to InspectOptions (#6591)

@balupton
Copy link
Contributor Author

Made an issue for repl.it https://repl.it/bugs/p/update-from-deno-v11-to-v13

@balupton
Copy link
Contributor Author

balupton commented Aug 18, 2020

Yep okay, it is specific to deno versions prior to I assume v1.2, as running deno v1.3 locally does not have this issue:

> deno --version
deno 1.3.0
v8 8.6.334
typescript 3.9.7
> deno run index.ts
Check file:///Users/balupton/Projects/auto/index.ts
{ value: 0.9213128912777346 }

Closing, as it is an issue with repl.it so the solution is there: https://repl.it/bugs/p/update-from-deno-v11-to-v13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant