// index.js
type complexThing = {
a: string
}
type Thing = {
x: number,
y: boolean,
z: complexThing
}
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing // this says my default export is a Thing
Alternatively, I wouldn't mind typing each of the object properties inline, but I think that's syntactically impossible:
export default {
// I don't know how to add type signatures here
x: 0, // number
y: true, // boolean
z: {a: 'hello'} // complexThing
}
What I don't want to do is store a variable just to to Flow type it:
// index.js
type complexThing = {
a: string
}
type Thing = {
x: number,
y: boolean,
z: complexThing
}
const myThing: Thing = {
x: 0,
y: true,
z: {a: 'hello'}
}
export default myThing
Export default is used when there is only one export to be made from a particular file and when importing this one element, we don't have to worry about giving the same name to our import. This combination of export and import allows us to implement modularity.
Export default means you want to export only one value the is present by default in your script so that others script can import that for use.
The difference between export default and export as default export { variable as default } exports the reference to the exported variable , whereas with export default variable , the importing modules do not receive the reference to the exported variable .
You are doing a typecast so you will need parens around the object, e.g. change
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing
to
export default ({
x: 0,
y: true,
z: {a: 'hello'}
} : Thing)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With