Skip to content

Leverage TypeScript 4.7 upgrade for deep type imports #2514

@dummdidumm

Description

@dummdidumm

Describe the problem

Right now we have to do ambient module hacks to define a public API through hand-written d.ts files for deep imports like @svelte/kit/hooks .

Describe the proposed solution

TypeScript 4.5 will support the exports field of a package.json along with a special import for types: microsoft/TypeScript#33079 (comment)

This means we could do

"exports": {
  "hooks": {
    "import": "./hooks.index.js",
    "types": "./types/hooks.d.ts"
  }
} 

If we do this we require people to use a compatible version of TypeScript which would be breaking change, so it would need to happen before 1.0 ideally.

Alternatives considered

  • Keep the hack as-is for now and change it in v2
  • Add a post-build-script which copies handwritten types to a location like hooks/index.d.ts where TS should pick it up

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions