sveltejs / sveltejs/kit

Type generation extensibility hooks

Open
#14,277 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types / typescript
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I want to create additional generated types like RequestEvent per route.

Describe the proposed solution

Something here

https://github.com/sveltejs/kit/blob/82a0e96e32fc0d1891d0cff2788d431a591710ab/packages/kit/src/core/sync/write_types/index.js#L181

That runs my own configured definition factories, the signature taking routes, route (and perhaps config, although why?) to append to declarations to be emitted when sveltekit types are generated

fn addDefinition({routes, route}) => {imports, declarations, exports} run and append them here

Maybe it could pick up a magic function from somewhere? Maybe a file that exists along the route directory structure? Falling back to tthe magic file at root or /app.

Alternatives considered

Script that runs and appends to each $types.d.ts after svelte has generated its types (unreliable)

Importance

would make my life easier

Additional Information

Allowing modification of core types is out of scope (probably not recommended at all?)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/kit/src/core/sync/write_types/index.js at the referenced lines, and trace how route types and declarations are assembled. Clarify the hook location, configuration or magic-file discovery, and the definition-factory contract; done means configured per-route types such as RequestEvent are emitted without post-generation scripts.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.