<@U01JVDKASAC> <@U01J5Q8HV5Z> any idea why I get t...
# help
m
@Frank @Jay any idea why I get the following typescript error for
Copy code
IdentityPoolId: auth.cognitoIdentityPoolId,
error:
Copy code
property) IdentityPoolId: string | undefined
Type 'string | undefined' is not assignable to type 'string | CfnOutputProps'.
  Type 'undefined' is not assignable to type 'string | CfnOutputProps'.ts(2322)
d
undefined
errors mean you need to institute a type guard or a fallback
type guard:
Copy code
if (!theThing) {
throw new Error("Nope")
}

// no longer undefined down here
This is true in JS too, just nothing to tell you so.
fallback:
setting: theThing ?? "ThisInstead"
TypeScript: Documentation - Narrowing (typescriptlang.org)
m
Thanks @Derek Kershner will check it out!
d
The error means Typescript is worried it will be undefined, so you need to make sure it isnt.
m
For anyone looking into this, I've replaced my code with
Copy code
if (!auth.cognitoIdentityPoolId) {
    throw new Error("auth.cognitoIdentityPoolId not defined")
  }

  // Show the auth resources in the output
  stack.addOutputs({
    Region: app.region,
    UserPoolId: auth.userPoolId,
    IdentityPoolId: auth.cognitoIdentityPoolId,
    UserPoolClientId: auth.userPoolClientId,
  });
And that did indeed resolve the issue. Thank you @Derek Kershner, will also pay more attention to versions.
t
@Mirza are you using js or ts?
m
I am trying to build the sst guide app in typescript
@thdxr