Skip to content

[Feature] Add types field to manifest for TypeScript support #6740

@grapgrap

Description

@grapgrap
  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Disclaimer: This content was written with the help of AI translation.

ref: #4834

Describe the user story

I want to make some util using @yarnpkg/parser.

But it did not have types field on manifest, I can't develop on typescript codebase.

Image

Describe the solution you'd like

According to this typescript docs, Package describe types field for type file.

// package.json
{
    "name": "my-package",
    "type": "module",
    "exports": {
        ".": {
            // Entry-point for `import "my-package"` in ESM
            "import": {
                // Where TypeScript will look.
                "types": "./types/esm/index.d.ts",
                // Where Node.js will look.
                "default": "./esm/index.js"
            },
            // Entry-point for `require("my-package") in CJS
            "require": {
                // Where TypeScript will look.
                "types": "./types/commonjs/index.d.cts",
                // Where Node.js will look.
                "default": "./commonjs/index.cjs"
            },
        }
    },
    // Fall-back for older versions of TypeScript
    "types": "./types/index.d.ts",
    // CJS fall-back for older versions of Node.js
    "main": "./commonjs/index.cjs"
}

Describe the drawbacks of your solution

The implementation is straightforward and follows TypeScript's official recommendations. There are no significant drawbacks as this change only adds type definitions without modifying existing functionality

Describe alternatives you've considered

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions