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

YAML stringify() speciously restricts input type to Record<string, unknown> #4506

Closed
hudlow opened this issue Mar 20, 2024 · 0 comments · Fixed by #4507
Closed

YAML stringify() speciously restricts input type to Record<string, unknown> #4506

hudlow opened this issue Mar 20, 2024 · 0 comments · Fixed by #4507
Labels
bug Something isn't working needs triage

Comments

@hudlow
Copy link
Contributor

hudlow commented Mar 20, 2024

Describe the bug

YAML stringify() has signature:

function stringify(
  obj: Record<string, unknown>,
  options?: DumpOptions,
): string

But restricting the input to Record<string, unknown> seems completely unnecessary, and is not enforced by the underlying implementation.

Steps to Reproduce

yaml-types.ts:

import { stringify } from "https://deno.land/[email protected]/yaml/mod.ts";

console.log(stringify([1, 2, 3]));
console.log(stringify("string"));
console.log(stringify(1.01));
console.log(stringify(true));

Executes correctly:

$ deno run yaml-types.ts
- 1
- 2
- 3

string

1.01

true

Fails type check:

Desktop $ deno check yaml-types.ts
Check file:///Users/hudlow/Desktop/yaml-types.ts
error: TS2345 [ERROR]: Argument of type 'number[]' is not assignable to parameter of type 'Record<string, unknown>'.
  Index signature for type 'string' is missing in type 'number[]'.
console.log(stringify([1, 2, 3]));
                      ~~~~~~~~~
    at file:///Users/hudlow/Desktop/yaml-types.ts:3:23

TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'Record<string, unknown>'.
console.log(stringify("string"));
                      ~~~~~~~~
    at file:///Users/hudlow/Desktop/yaml-types.ts:4:23

TS2345 [ERROR]: Argument of type 'number' is not assignable to parameter of type 'Record<string, unknown>'.
console.log(stringify(1.01));
                      ~~~~
    at file:///Users/hudlow/Desktop/yaml-types.ts:5:23

TS2345 [ERROR]: Argument of type 'boolean' is not assignable to parameter of type 'Record<string, unknown>'.
console.log(stringify(true));
                      ~~~~
    at file:///Users/hudlow/Desktop/yaml-types.ts:6:23

Found 4 errors.

Expected behavior

Type checking to succeed.

Environment

  • OS: macOS 14.3.1
  • deno version: 1.38.2 (release, aarch64-apple-darwin)
  • std version: 0.220.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant