作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Google Cloud Platform 和 Typescript。
我正在处理一些应该实现特定 GPC 类型的代码和变量。喜欢:
import { protos } from "@google-cloud/aiplatform";
class myClass {
public async getModelById(id: string): Promise<protos.google.cloud.aiplatform.v1beta1.IModel>
{ /* ... */ }
public async getTrainingPipelineById(id: string): Promise<protos.google.cloud.aiplatform.v1beta1.ITrainingPipeline>
{ /* ... */ }
}
我只想导入
类型 ,
类(class) 和
枚举 我想使用,例如
import { IModel, ITrainingPipeline } from "@google-cloud/aiplatform".protos.google.cloud.aiplatform.v1beta1 ;
// I know that the code above does not works, but you got the idea
class myClass {
public async getModelById(id: string): Promise<IModel>
{ /* ... */ }
public async getTrainingPipelineById(id: string): Promise<ITrainingPipeline>
{ /* ... */ }
}
如何从模块内部的子命名空间导入单个类型、类或枚举?
最佳答案
总之,you can't do that .
从链接总结:即使语法看起来相似,导入命名导入与解构对象不同,因此您不能像解构那样嵌套它。您将不得不使用两个语句:
import { protos } from "@google-cloud/aiplatform";
let {google: {cloud: {aiplatform: {v1beta1: {IModel, ITrainingPipeline}}}}} = protos;
// or, perhaps more readably
let {IModel, ITrainingPipeline} = protos.google.cloud.aiplatform.v1beta1;
Playground
关于typescript - 如何从 Typescript 模块内部的子命名空间导入单个类型、类、常量或枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66250577/
我是一名优秀的程序员,十分优秀!