1

Is there a way I can import a module(?) (a set of functions) in typescript and be able to refer to these functions without the Module. prefix?

For example:

import * as Operations from './Operations';

Can I reference Operations.example() as example()? Essentially merging the 'namespace'?

2
  • What about just importing example from ./Operations? can you please show how Operations is? does it have a default export? Commented Mar 28, 2019 at 16:06
  • I am free to define the Operations file in any way. But essentially I want to define a set of functions that can be imported anywhere. Commented Mar 28, 2019 at 16:32

1 Answer 1

1

You can do:

import { example } from './Operations';

This assumes you are exporting example from the file as a named export.

// ./Operations
export function example () {...}

Typescript Module Documentation

Sign up to request clarification or add additional context in comments.

2 Comments

This requires I write out all the functions, is there way to specify all of the exported functions?
@ChrisStryczynski unfortunately no. If you have each as a named export you either need to specify each in a {} or use import * as namespace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.