11
votes

This is how I export and import typescript interface for objects. Everything works just fine. Giving this as an example of what I'm trying to achieve, but with functions.

Module 1

export interface MyInterface {
  property: string;
}

Module 2

import {MyInterface} from './module1';

const object: MyInterface = {
    property: 'some value'
};

The code below gives me an error "TS2304: Cannot find name 'myFunction'". How do I export and import a function type?

Module 1

export let myFunction: (argument: string) => void;

Module 2

import {myFunction} from './module1';

let someFunction: myFunction; 
1
export type myFunction = (arg: string) => void ?Gerrit0
@Gerrit0, woohoo! Thank you sir! It works! So simple!manidos
@Gerrit0 please make an answer out of your comment, so other people know as well.toskv

1 Answers

25
votes

This is how it's done:

Module 1

export type myFunction = (arg: string) => void

Module 2

import {myFunction} from './module1';

let someFunction: myFunction;