Alex Ngo
Alex Ngo

Reputation: 985

How to get type from export?

If I was exporting

baz.ts

export default {
  foo: 5,
  bar: 'test'
}

then I was to do

otherFile.ts

import baz from './test.js'

How would I got about getting the type of baz?

Upvotes: 2

Views: 71

Answers (2)

gsamaras
gsamaras

Reputation: 73366

With typeof baz, you get the type of baz, like this:

type bazType = typeof baz;

Read more in Type Queries and typeof in TypeScript.

Upvotes: 0

Paarth
Paarth

Reputation: 10377

How about

type bazType = typeof baz;

Upvotes: 2

Related Questions