How can I enter a default export using a stream?

How can I enter a default export using a stream? Is there any way to complete this process?

Desired Result:

// 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

Valid Alternative:

As an alternative, I would not mind writing each of the properties of an object into a string, but I think it is syntactically impossible:

export default {
 // I don't know how to add type signatures here
 x: 0, // number
 y: true, // boolean
 z: {a: 'hello'} // complexThing
}

Not what I want:

What I do not want to do is save the variable just so that the stream type:

// 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
+4
source share
1 answer

You do typecast , so you will need parsers around the object, for example. change

export default {
  x: 0,
  y: true,
  z: {a: 'hello'}
} : Thing

to

export default ({
  x: 0,
  y: true,
  z: {a: 'hello'}
} : Thing)
+5
source

Source: https://habr.com/ru/post/1668570/


All Articles