#export typescript

14 messages · Page 1 of 1 (latest)

analog fox
#

hello lets say for example i have file at folder/src/index.ts which contains
export { demo, test } from '@/doing/stuff'
is it possible to use demo function in a way to just import folder/src/index into my file?

candid parcel
#

can you elaborate on what exactly you're trying to achieve?

analog fox
candid parcel
#

yes, that's what export is for

#

that's like, the single thing that statement allows you to do

analog fox
#

alright

upbeat zealot
#

This helped me better understand how exports work:

(If I understand it correctly)

Every export is basically a default export

e.g.

exporter.ts


export default { foo: 'bar' }

importer.ts

import GiveAnyName from 'exporter' // default
// { foo: 'bar' }
import { foo } from 'exporter' // destructed
// foo = 'bar'

Hint. In JavaScript there is only 'default export':

module.exports = { foo: 'bar' }
sharp ledge
#

i might be confused about what you're trying to get across, but if i have a file named ./exporter.js with this contents:

export default { foo: 'bar' }

and i try to import that via:

import { foo } from './exporter.js'

it doesn't work (at least with standardized ECMAScript modules, not sure about other module systems)

#

default exports are their own separate thing, and the import { … } from … syntax is not really the same as "destructuring" (though i see the analogy)

upbeat zealot
#

You are right

#

I had no idea

sharp ledge
candid parcel