I am working with Google Cloud Platform and Typescript.
I've working with some code and varialbes that should implement specific GPC types. like:
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>
{ /* ... */ }
}
I would like to import only types, classes and enums I would like to use, for instance
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>
{ /* ... */ }
}
How can i import a single type, class or enum from a sub namespace inside from a module?
In short, you can't do that.
Summarizing from the link: even though the syntax looks similar, importing named imports is not the same thing as destructuring an object so you can't nest it like you can with destructuring. You will have to use two statements:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With