0

I have seen Typescript code that looks like this:

const { PUBLIC_JWKS } = event.secrets.PUBLIC_JWKS;

and I am having trouble understanding what this means.

My first question is: Is this even a Typescript thing, or a holdover from Javascript?

Second: If it is a Typescript thing, what, exactly does it mean? It seems string to have an object be a const value.

Nick Hodges
  • 16,902
  • 11
  • 68
  • 130

2 Answers2

2

My first question is: Is this even a Typescript thing, or a holdover from Javascript?

holdover from Javascript and it is called Destructuring assignment

const { myId } = props;

is the same as :

const myId = props.myId 

so here it is most probably :

const { PUBLIC_JWKS } = event.secrets;

or maybe event.secrets.PUBLIC_JWKS is an object with PUBLIC_JWKS property who knows

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38
0

You mentioned typescript code "that looks like this". So, is it exactly that code? Or are you improvising. Because...

I think this should be:

const { PUBLIC_JWKS } = event.secrets

No TypeScript here.

Just creating a new const variable PUBLIC_JWKS, and assigning it the value of event.secrets.PUBLIC_JWKS; (By extracting it from that property name)

InfiniteStack
  • 430
  • 2
  • 9