Skip to content

Commit ed3bcea

Browse files
committed
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.
1 parent 498e232 commit ed3bcea

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

packages/client/src/client.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import {ClientResponse} from "@sendgrid/client/src/response";
55
declare class Client {
66
constructor();
77

8+
/**
9+
* Class itself, attached at runtime via `module.exports.Client = Client`.
10+
* Lets `import client = require("@sendgrid/client")` consumers reach the
11+
* class via `client.Client`.
12+
*/
13+
Client: typeof Client;
14+
815
/**
916
* Set the SendGrid API key.
1017
*/
@@ -52,7 +59,4 @@ declare class Client {
5259
}
5360

5461
declare const client: Client;
55-
// @ts-ignore
56-
export = client
57-
58-
export {Client};
62+
export = client;

packages/mail/src/mail.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import {Client} from "@sendgrid/client";
1+
import sgClient = require("@sendgrid/client");
22
import {ClientResponse} from "@sendgrid/client/src/response";
33
import {ResponseError} from "@sendgrid/helpers/classes";
44
import {MailDataRequired} from "@sendgrid/helpers/classes/mail";
55

6+
type Client = InstanceType<typeof sgClient.Client>;
7+
68
declare class MailService {
9+
/**
10+
* Class itself, attached at runtime via `module.exports.MailService = MailService`.
11+
*/
12+
MailService: typeof MailService;
13+
714
/**
815
* SendGrid API key passthrough for convenience.
916
*/
@@ -41,10 +48,4 @@ declare class MailService {
4148
}
4249

4350
declare const mail: MailService;
44-
// @ts-ignore
4551
export = mail;
46-
47-
export {MailService};
48-
export {MailDataRequired};
49-
export {ClientResponse};
50-
export {ResponseError};

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"noEmit": true,
44
"module": "commonjs",
55
"target": "es6",
6-
"baseUrl": ".",
6+
"types": ["node"],
77
"paths": {
8-
"@sendgrid/*": ["packages/*"]
8+
"@sendgrid/*": ["./packages/*"]
99
}
1010
},
1111
"include": [

0 commit comments

Comments
 (0)