Skip to content

fix: make types compile under TypeScript 7.0#1458

Open
FelipeLahti wants to merge 1 commit into
sendgrid:mainfrom
FelipeLahti:fix/typescript-7-export-conflict
Open

fix: make types compile under TypeScript 7.0#1458
FelipeLahti wants to merge 1 commit into
sendgrid:mainfrom
FelipeLahti:fix/typescript-7-export-conflict

Conversation

@FelipeLahti

@FelipeLahti FelipeLahti commented Apr 27, 2026

Copy link
Copy Markdown

Fixes #1454

@sendgrid/client and @sendgrid/mail mix export = instance with export {Class} and silence the diagnostic with // @ts-ignore. TypeScript 7.0 (the Go-port tsgo beta) tightens the rule and surfaces it in every consumer:

error TS2616: 'Client' can only be imported by using
'import Client = require("@sendgrid/client")' or a default import.

Drop the @ts-ignore and the redundant named export by modelling the runtime exactly — module.exports.Client = Client becomes a Client: typeof Client instance member. import { Client } from "@sendgrid/client", new client.Client(), and client.setApiKey(...) all keep working unchanged.

Same shape applied to MailService in packages/mail/src/mail.d.ts.

tsconfig.json also bumped to TS 7.0 minimums so test/typescript/*.ts keeps type-checking under tsgo: baseUrl removed, leading ./ added to path mappings, types: ["node"] declared explicitly.

Verification

Existing test/typescript/{client,mail}.ts fixtures pass unchanged under both compilers — including import { Client } from "@sendgrid/client"; new Client() and setClient(client: Client):

$ tsc --noEmit -p tsconfig.json    # tsc 5.9.3 → exit 0
$ tsgo --noEmit -p tsconfig.json   # @typescript/native-preview 7.0.0-dev → exit 0

No runtime change. No consumer-visible type change.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified
Both `@sendgrid/client` and `@sendgrid/mail` ship .d.ts files that
mix `export = instance` with `export {Class}` and silence the
diagnostic with `// @ts-ignore`. Pre-7.0, downstream consumers paid
no cost for this since named imports of the class still resolved.
TS 7.0 (the Go-port `tsgo` beta) tightens the rule and surfaces
TS2616 in every consumer that imports `Client` or `MailService`:

    error TS2616: 'Client' can only be imported by using
    'import Client = require("@sendgrid/client")' or a default import.

The fix mirrors the runtime: `module.exports = new Client();
module.exports.Client = Client;`. Modeling that as a `Client`
instance with a `Client: typeof Client` instance member lets TS
expose the class through `client.Client` AND through the named
import `import { Client } from "@sendgrid/client"` without any
escape hatches. Same pattern for MailService. Existing TS test
fixtures (incl. `new Client()` and `setClient(client: Client)`)
keep passing under both tsc 5.9 and tsgo 7.0 unchanged.

Also bring tsconfig.json up to TS 7.0 minimums so the test fixtures
type-check under tsgo: drop the removed `baseUrl`, add the now-
required leading `./` to path mappings, and declare `types: ["node"]`
explicitly (auto-load of all @types is gone in 7.0).

Verified with tsc@5.9.3 and @typescript/native-preview@7.0.0-dev.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant