Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe leaks NodeJS types if imported #2243

Open
richardsimko opened this issue Dec 22, 2024 · 1 comment
Open

Stripe leaks NodeJS types if imported #2243

richardsimko opened this issue Dec 22, 2024 · 1 comment

Comments

@richardsimko
Copy link

richardsimko commented Dec 22, 2024

Describe the bug

Due to weird behavior in TypeScript (Mainly microsoft/TypeScript#37053) the use of /// <reference types="node" /> will leak to any consumers of a type definition file.

This means that if one wants to use some of the Stripe types, for example to define an interface for an API response (Which gets imported in the client) this will leak NodeJS types to all the client side code as well.

To Reproduce

  1. Observe the Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node and then add 'node' to the types field in your tsconfig. error as expected
  2. Change the code to import a type from stripe
  3. Observe the error disappearing

Expected behavior

The error regarding process persists

Code snippets

Minimal tsconfig.json:

{
  "include": "test.ts",
  "compilerOptions": {
    "lib": ["ES2022", "DOM", "DOM.Iterable"],
    "types": []
  }
}

test.ts before importing:

// TS error as expected
process.exit()

test.ts after importing:

import type { Stripe } from 'stripe';

const foo: Stripe.Price.Recurring.Interval;

// No error 
process.exit()

OS

macos

Node version

any

Library version

stripe-node 17.4.0

API version

N/A

Additional context

No response

@xavdid-stripe
Copy link
Member

Hey @richardsimko, thanks for the report here! Given that it's a typescript bug, there's not much we can do here in the short term. Given that this package is primarily meant for use in Node environments, the node typings are important.

Long term, we could potentially look into separating the type definitions from the runtime code (to better support type-only usage) but it's not currently a priority for us.

I'll leave this issue open in the meantime if other folks want to 👍 it or have further feedback.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants