Feature requests: Typescript definitions
Problem
Hi, Since typescript popularity is on the rise and there are no community definitions available for stripe-node I would very much like Typescript definitions. This will help both Typescript users and normal JS users with IDEs that support them like WebStorm and VSCode (even Sublime and Atom have JS hinting plugins that support them). I find using type definitions much easier than going through the documentation. In addition not all the documentation is up to date since I see the functions can optionally return promises if a callback is not passed and it's not documented.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Add TypeScript Definitions for stripe-node
The lack of TypeScript definitions for the stripe-node library is due to the absence of official type declaration files, which are necessary for TypeScript to provide type checking and IntelliSense features. This results in a suboptimal developer experience for TypeScript users, as they cannot leverage the benefits of type safety and autocompletion in their IDEs.
Awaiting Verification
Be the first to verify this fix
- 1
Create TypeScript Declaration Files
Develop TypeScript declaration files (.d.ts) for the stripe-node library to define the types for its functions, classes, and objects. This will enable TypeScript users to benefit from type checking and IDE support.
typescriptdeclare module 'stripe' { export interface StripeOptions { apiKey: string; // Add other options as needed } export class Stripe { constructor(options: StripeOptions); charges: Charges; // Define other properties and methods } export interface Charges { create(params: ChargeCreateParams): Promise<Charge>; // Define other methods } export interface ChargeCreateParams { amount: number; currency: string; // Add other parameters as needed } export interface Charge { id: string; // Define other properties } } - 2
Publish Type Definitions
Once the TypeScript declaration files are created, publish them to DefinitelyTyped or include them directly in the stripe-node repository. This will make the type definitions available to the community and ensure they are maintained alongside the library.
- 3
Update Documentation
Update the official documentation of the stripe-node library to include information about the TypeScript definitions, including how to install and use them. Ensure that any discrepancies, such as optional promise returns, are documented accurately.
- 4
Test Type Definitions
Create a test project that uses the stripe-node library with the new TypeScript definitions to ensure that all types are correctly defined and that the library functions as expected with TypeScript. This will help catch any issues before the definitions are published.
typescriptimport Stripe from 'stripe'; const stripe = new Stripe('your_api_key'); stripe.charges.create({ amount: 1000, currency: 'usd' });
Validation
Confirm that TypeScript users can import and use the stripe-node library without type errors. Check that IDEs like VSCode and WebStorm provide autocompletion and type hints for the library's functions and classes.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep