Skip to content

Design Proposal: Leverage side-effects: false in package.json for tree-shaking friendly modules #19202

Closed
@donaldpipowitch

Description

@donaldpipowitch

Before You Start

I think this design proposal aligns with TypeScript Design Goals and helps TypeScript authors to write more efficient packages (and help the JavaScript ecosystem in general this way).

The are very similar existing suggestions, but it looks like none of them leverages side-effects: false in package.json directly.

E.g. there is

Defining a Scenario

As a lib author I'd like to create packages which are easy to consume by tools and allow features like efficient tree shaking. I'd like to re-use existing conventions to flag my package with a certain feature (in this case side-effects: false in package.json). I'd like TypeScript to assist me in writing packages which fulfil this constraint.

So basically:

  • When I write a TypeScript-based package...
  • ...and set side-effects: false in package.json...
  • ...I want the TypeScript compiler to throw errors, when I invalidate this constraint.

Language Feature Checklist

This change should be able to be introduced without a breaking change and should keep backwards compatibility with the JS language.

Side effects free packages

See here for an example.


cc @TheLarkInn

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions