Skip to content

Instantly share code, notes, and snippets.

@Andromelus
Forked from joduplessis/cookie-typescript-utils.ts
Last active October 6, 2020 17:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andromelus/4a6063edd927c59351b43fa1b3f57b94 to your computer and use it in GitHub Desktop.
Save Andromelus/4a6063edd927c59351b43fa1b3f57b94 to your computer and use it in GitHub Desktop.
Setting, deleting and retrieving cookies in Typescript.
@michael-freidgeim-webjet

I have the same error, that original gist has
[tsl] ERROR in c:common\cookieUtils.ts(20,16)
TS2532: Object is possibly 'undefined'.

@btwatts
Copy link

btwatts commented Oct 6, 2020

Try adding a return after the if block to cover that case.
if (parts.length === 2) {
...return the good stuff....
}
return undefined; // or null or empty string or whatever you think is appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment