fix: make types compile under TypeScript 7.0#1458
Open
FelipeLahti wants to merge 1 commit intosendgrid:mainfrom
Open
fix: make types compile under TypeScript 7.0#1458FelipeLahti wants to merge 1 commit intosendgrid:mainfrom
FelipeLahti wants to merge 1 commit intosendgrid:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1454
@sendgrid/clientand@sendgrid/mailmixexport = instancewithexport {Class}and silence the diagnostic with// @ts-ignore. TypeScript 7.0 (the Go-porttsgobeta) tightens the rule and surfaces it in every consumer:Drop the
@ts-ignoreand the redundant named export by modelling the runtime exactly —module.exports.Client = Clientbecomes aClient: typeof Clientinstance member.import { Client } from "@sendgrid/client",new client.Client(), andclient.setApiKey(...)all keep working unchanged.Same shape applied to
MailServiceinpackages/mail/src/mail.d.ts.tsconfig.jsonalso bumped to TS 7.0 minimums sotest/typescript/*.tskeeps type-checking undertsgo:baseUrlremoved, leading./added to path mappings,types: ["node"]declared explicitly.Verification
Existing
test/typescript/{client,mail}.tsfixtures pass unchanged under both compilers — includingimport { Client } from "@sendgrid/client"; new Client()andsetClient(client: Client):No runtime change. No consumer-visible type change.
Checklist