Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在typescript中使用条带类型_Typescript_Stripe Payments - Fatal编程技术网

如何在typescript中使用条带类型

如何在typescript中使用条带类型,typescript,stripe-payments,Typescript,Stripe Payments,我正在尝试使用环回框架创建一个应用程序,它使用typescript。我想使用Stripe,我安装了Stripe和@types/Stripe,因为据我所知,Typescript需要明确的类型 我正在导入条纹作为 从“条带”导入*作为条带 我也想导入类型,所以我正在做 从“@types/Stripe”导入*作为条带 但是,我得到了一个错误: 无法导入类型声明文件。考虑导入“条纹”代替“@类型/条带”< /P> 如何导入类型,以便使用它们来声明函数返回等?通过安装stripe和@types/strip

我正在尝试使用环回框架创建一个应用程序,它使用typescript。我想使用Stripe,我安装了Stripe和@types/Stripe,因为据我所知,Typescript需要明确的类型

我正在导入条纹作为 从“条带”导入*作为条带

我也想导入类型,所以我正在做 从“@types/Stripe”导入*作为条带

但是,我得到了一个错误: 无法导入类型声明文件。考虑导入“条纹”代替“@类型/条带”< /P>
如何导入类型,以便使用它们来声明函数返回等?

通过安装stripe和@types/stripe,您做得很正确。但是,您不需要在源文件中导入类型声明

import * as Stripe from 'stripe';

export const stripe = new Stripe('whateverkey');

function createHeader(): Stripe.HeaderOptions { // use stripe types for return type
  return 'stripe header';
}
如果您使用VSCode或IDE编辑器,它应该为您提供如下所示的IntelliSense


希望通过安装stripe和@types/stripe,它能帮助您正确地执行操作。但是,您不需要在源文件中导入类型声明

import * as Stripe from 'stripe';

export const stripe = new Stripe('whateverkey');

function createHeader(): Stripe.HeaderOptions { // use stripe types for return type
  return 'stripe header';
}
如果您使用VSCode或IDE编辑器,它应该为您提供如下所示的IntelliSense


希望对您有所帮助

如果您直接使用条带节点[1],它现在支持typescript并定义了类型。对于找到此项并使用stripe节点中的类型的用户,可以按如下方式导入stripe:

import Stripe from 'stripe';
const stripe = new Stripe(
  'sk_test_...', 
  {
    apiVersion: '2019-12-03',
    typescript: true,
  }
);

[1]

如果直接使用条带节点,它现在支持typescript并定义了类型。对于找到此项并使用stripe节点中的类型的用户,可以按如下方式导入stripe:

import Stripe from 'stripe';
const stripe = new Stripe(
  'sk_test_...', 
  {
    apiVersion: '2019-12-03',
    typescript: true,
  }
);

[1]

您不需要显式导入声明,只需从“stripe”导入名称即可。因此,是否需要单独导入类型?像从'stripe'导入{icCustomer}或在声明中执行stripe.icCustomer?您没有显式导入声明,只是从'stripe'导入名称。那么对类型执行单独导入吗?像从'stripe'导入{icCustomer}或者在声明中执行stripe.icCustomer?非常感谢!所以我不需要再下载@types/stripe了?不,这些是最近作为stripe节点库的一部分发布的。非常感谢!所以我不需要再下载@types/stripe了?不,这些是最近作为stripe节点库的一部分发布的。