Skip to content

Make VFileContents generic to support processors that return objects #45

@sandhose

Description

@sandhose

Subject of the feature

Right now, in the type definitions, VFileContents is either a Buffer or a string. In some unified processors, the VFile content is an object, which makes them impossible to typedef them correctly.

Problem

For example, remark-react returns a ReactNode in its compiler, making it impossible to define types for it. Please note that patches would also be necessary in unified types to support processors that modify the VFile content type.

remark-react is not the only compiler concerned by this. I'll open issues in the projects I mentioned here related to this.

Expected behaviour

VFile should be a generic for its content. The default can be Buffer | string in order to be fully backward-compatible. With this done, we should be able to declare the remark-react compiler output as something like VFile<Contents = ReactNode>.

Alternatives

An alternative would be to declare the VFileContents as any. It would be a lot easier to do, but we would loose a lot of strict type checking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions