最近,Stripe用version 8将类型添加到它们的条带节点库中,这取代了对DefinitelyTyped中单独的@type/stripe的需求。在节点TypeScript环境中,使用这些类型很简单,但我想知道在编译为浏览器JavaScript的客户端TypeScript应用程序(Angular)中使用这些类型是否可行。
它似乎适用于任何我想要添加Stripe类型的npm install --save stripe和import Stripe from 'stripe',但考虑到这是一个节点库,我想确保我没有遗漏任何明显的东西。是否需要在客户端应用程序中导入为节点设计的库?
编辑:
要明确的是,我并不是在问是否可以在我的客户端充分利用stripe-node。那将是一个巨大的安全风险。既然库已经内置了类型,如果我们能够在客户端类型记录中引用这些类型,那就太好了。
发布于 2020-02-24 17:48:33
条形节点的类型不适用于Stripe.js,您需要使用以下内容:https://github.com/stripe/stripe-js
npm install @stripe/stripe-js
请参阅有关TypeScript支持的部分:https://github.com/stripe/stripe-js#typescript-support
发布于 2020-07-27 16:13:20
只有当您在前端代码中使用您的服务器机密时,才会有顾虑。只要您没有这样做&只对前端的类型定义使用服务器库,就根本没有问题.
发布于 2021-09-20 11:15:22
我使用一个monorepo包从TypeScript库导出stripe-node接口。
project
└── packages
├── common
└── web从@stripe/stripe-js
stripe-node到web,Stripe发生冲突,这可能会被错误地使用(例如,在使用expand进行条带API调用时使用expand
扩展类型)。
// project/packages/common/stripe.ts
import { Stripe } from "stripe";
type StripeInvoice = Stripe.Invoice;
type StripeSubscription = Stripe.Subscription;
type StripeSubscriptionList = Stripe.Response<
Stripe.ApiList<Stripe.Subscription>
>;
type StripeCustomer = Stripe.Customer;
export {
StripeInvoice,
StripeCustomer,
StripeSubscription,
StripeSubscriptionList,
};// project/packages/web/request.ts
import { StripeSubscriptionList } from "@project/common/stripe";
const listSubscriptions = async () => {
// Wrapper function for the fetch API
return await fetchAPI<StripeSubscriptionList>("subscriptions", {
method: "GET",
});
};https://stackoverflow.com/questions/60381028
复制相似问题