From ed3bcea755bf66d5ca0cdad22496d2c69c667fd1 Mon Sep 17 00:00:00 2001 From: Felipe Lahti Date: Mon, 27 Apr 2026 12:34:52 -0300 Subject: [PATCH] fix: make types compile under TypeScript 7.0 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. --- packages/client/src/client.d.ts | 12 ++++++++---- packages/mail/src/mail.d.ts | 15 ++++++++------- tsconfig.json | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/client/src/client.d.ts b/packages/client/src/client.d.ts index 84075d1f9..c1696cf78 100644 --- a/packages/client/src/client.d.ts +++ b/packages/client/src/client.d.ts @@ -5,6 +5,13 @@ import {ClientResponse} from "@sendgrid/client/src/response"; declare class Client { constructor(); + /** + * Class itself, attached at runtime via `module.exports.Client = Client`. + * Lets `import client = require("@sendgrid/client")` consumers reach the + * class via `client.Client`. + */ + Client: typeof Client; + /** * Set the SendGrid API key. */ @@ -52,7 +59,4 @@ declare class Client { } declare const client: Client; -// @ts-ignore -export = client - -export {Client}; +export = client; diff --git a/packages/mail/src/mail.d.ts b/packages/mail/src/mail.d.ts index fa827498d..0fc8511d1 100644 --- a/packages/mail/src/mail.d.ts +++ b/packages/mail/src/mail.d.ts @@ -1,9 +1,16 @@ -import {Client} from "@sendgrid/client"; +import sgClient = require("@sendgrid/client"); import {ClientResponse} from "@sendgrid/client/src/response"; import {ResponseError} from "@sendgrid/helpers/classes"; import {MailDataRequired} from "@sendgrid/helpers/classes/mail"; +type Client = InstanceType; + declare class MailService { + /** + * Class itself, attached at runtime via `module.exports.MailService = MailService`. + */ + MailService: typeof MailService; + /** * SendGrid API key passthrough for convenience. */ @@ -41,10 +48,4 @@ declare class MailService { } declare const mail: MailService; -// @ts-ignore export = mail; - -export {MailService}; -export {MailDataRequired}; -export {ClientResponse}; -export {ResponseError}; diff --git a/tsconfig.json b/tsconfig.json index b8d1ada33..f61d45bf8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,9 +3,9 @@ "noEmit": true, "module": "commonjs", "target": "es6", - "baseUrl": ".", + "types": ["node"], "paths": { - "@sendgrid/*": ["packages/*"] + "@sendgrid/*": ["./packages/*"] } }, "include": [