Home > Software design >  python import { p.* } from "./app" in typescript
python import { p.* } from "./app" in typescript

Time:03-20

I was wandering if there is an equivalent to this code in python import { p.* } from "./app" in typescript

currently I am achiving it like this but this is tedious work and it does not even work for all functions:

import { p as p5 } from "./app";

const translate = p5.translate;
const rotate = p5.rotate;
const fill = p5.fill;
const strokeWeight = p5.strokeWeight;
const stroke = p5.stroke;

export { translate, rotate, fill, strokeWeight, stroke }

CodePudding user response:

No. There is no wildcard import feature in TypeScript (or ECMAScript).

Instead of the "tedious work" of those re-exports, you should use an editor/IDE that can deal with adding import statements, so you don't need to do it by hand.

CodePudding user response:

You can use object destruction in export statements, so this should work, which is a bit cleaner:

export const { translate, rotate, fill, stroke } from './app'

A cleaner option would be to have a file that has everything you want to export from it as a separate file, and use export * from in here instead, like so:

// p.js
export { translate, rotate, ... } // use the same consts you would do in './app'
// other.js
export * from './p'
  • Related