Skip to content

🚀 Feature: Use namespace import from typescript, not default import #711

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Bug Report Checklist

Overview

Coming over from #588: there's interest in switching from default-importing TypeScript to namespace-importing:

- import ts from "typescript";
+ import * as ts from "typescript";

Prettier's https://github.com/prettier/prettier/blob/96d2fe439dcf784806d6543c422fe6ffe679ca4c/scripts/build/config.js#L278 is an example of downstream consumers that have to do work to manually edit files. They do so because tree shaking works better for namespace imports apparently.

Speaking of which, @fisker I have a vague memory of seeing an explanation but now can't find it. Why does a default import not work well for tree-shaking? Are there tracking issues for tools to support it?

Additional Info

TypeScript only added support for a named import in https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#easier-api-consumption-from-ecmascript-modules. I think this is blocked on ts-api-utils no longer supporting earlier TypeScript versions.

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: blockedWaiting for something else to be resolved 🙅type: featureNew enhancement or request 🚀

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions