Skip to content

writeFileSync data as Object throws type error despite docs listing Object as a supported type #39152

Closed
@JakobJingleheimer

Description

@JakobJingleheimer
  • Version: 14.17.0 & 16.4.0
  • Platform: local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:31 PDT 2021; root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64
  • Subsystem: FS / Docs

What steps will reproduce the bug?

import { writeFileSync } from 'fs';

writeFileSync('test.log', { foo: 'bar' });

How often does it reproduce? Is there a required condition?

100% (no special conditions)

What is the expected behavior?

The type(s) for data listed in the docs to work.

What do you see instead?

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an
instance of Buffer, TypedArray, or DataView. Received an instance of Object
    at writeFileSync (node:fs:2136:5)

Additional information

fs docs for 14.x and 16.x both include <Object> as a type for writeFileSync's data argument:

data <string> | <Buffer> | <TypedArray> | <DataView> | <Object>

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions