ReviewOS

stacks/dtsx

Malformed .d.ts output: getter syntax, missing semicolons, default values in declarations

#3093
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Summary

dtsx generates three types of invalid .d.ts syntax that cause TypeScript errors in downstream consumers.

Bug 1: Getter accessor syntax

Source:

export const ENV = {
  get TRACE() { return process.env.PICKIER_TRACE === '1' },
}

dtsx output (broken):

export declare const ENV: {
  get TRACE: () => unknown;
}

Correct output:

export declare const ENV: {
  get TRACE(): unknown;
}

TypeScript error: TS1005: '(' expected.

The getter is emitted as get PROP: () => T (property with function type) instead of get PROP(): T (accessor declaration).

Affected package: pickier@0.1.21 — dist/utils.d.ts lines 52-56

Bug 2: Missing semicolons between object type properties

Source:

export function resilient(config: { sentryDsn?: string, bugsnagApiKey?: string, services?: string[] } = {}) {}

dtsx output (broken):

resilient: (config: { sentryDsn?: string bugsnagApiKey?: string services?: string[] } = {}) => any

Correct output:

resilient: (config: { sentryDsn?: string; bugsnagApiKey?: string; services?: string[] }) => any

TypeScript error: TS1005: ';' expected.

Properties in inline object types need ; or , separators.

Affected package: @stacksjs/bun-router — dist/errors/error-handler.d.ts line 21

Bug 3: Default parameter values in declarations

Source:

function resilient(config: { sentryDsn?: string } = {}) {}

dtsx output (broken):

resilient: (config: { sentryDsn?: string } = {}) => any

Correct output:

resilient: (config?: { sentryDsn?: string }) => any

Default values (= {}) are not valid in .d.ts files. Parameters with defaults should be marked as optional (?) instead.

Impact

These bugs cause typecheck failures in any downstream package that imports from pickier or @stacksjs/bun-router:

  • ts-analytics — 11 typecheck errors from bun-router
  • ts-video-player — 7 typecheck errors from pickier

Versions

  • bun-plugin-dtsx: 0.9.13
  • pickier: 0.1.21
  • @stacksjs/bun-router: latest

Sign in to comment on this issue.