2

I'm currently creating my first declaration file for a foreign library(react-native-background-timer). The library though has an default export I'm not sure how to declare in the index.d.ts file.

This is the default export of the library:

export default new BackgroundTimer();

I'm aware how to declare exported classes, but what's the best way to declare an exported class instance?

My first approach was:

declare class BackgroundTimer {
    [...]
}

declare const _BackgroundTimer: BackgroundTimer;
export default _BackgroundTimer;

1 Answer 1

2

Yes this is the way to declare default export that exports an instance, it's documented on the breaking changes page for TypeScript 2.6. Previously it was possible to do it in the declaration file in one line exactly as in the code

export default new BackgroundTimer();

but having arbitrary expressions in export was disallowed.

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

1 Comment

Thanks! I totally missed that in the documentation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.