0

I'm having a problem making this code

const AuthInit = (props: any) => {
    let {children: WithChildren} = props;
...
return showSplashScreen ? <LayoutSplashScreen /> : <>{children}</>
}

compile, I have to use props.children and remove the destructured line for it to work. Why is that? and how can I make it work

type WithChildren = {
  children?: ReactNode
}

error: TS2304: Cannot find name 'children'.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
usertest
  • 2,140
  • 4
  • 32
  • 51
  • 1
    You are destructuring into an alias, not giving a type annotation so your variable name is `WithChildren`. (also children is of type `ReactNode` not `WithChildren` according to your type) – pilchard Apr 19 '23 at 00:44
  • 2
    At any rate, `let {children: WithChildren} = props;` means "take the `children` property from `prop` and assign it to the variable called `WithChildren`. Which is why `children` does not exist as a variable. It's just `let {children} = props;` to destructure the property `children` to the variable `children`. – VLAZ Apr 19 '23 at 00:50

0 Answers0