DEV Community

Discussion on: Deploy Netlify Functions with TypeScript

Collapse
 
parkan profile image
Arkadiy Kukarkin

the sample snippet doesn't build for me:

error TS2339: Property 'msg' does not exist on type '{ [name: string]: string; } | null'.

8   const { msg } = event.queryStringParameters
Enter fullscreen mode Exit fullscreen mode
Collapse
 
parkan profile image
Arkadiy Kukarkin • Edited

fixed it as follows:

interface EchoQueryParams {
  msg?: String
}
...
const { msg } = event.queryStringParameters as EchoQueryParams

(note, this won't actually enforce runtime type checks, but it will make it compile)

Collapse
 
atila profile image
Atila Fassina • Edited

Interesting... it works well for me, code runs as expected and ts-checks return no warnings or errors

❯ tsc --version
Version 4.0.3

❯ yarn ts-check
yarn run v1.22.5
$ tsc --noEmit --lib ES2015 ./src/*.ts
✨  Done in 0.77s.

Plus { msg } definitely exists in type [name: string] : string 😜

Collapse
 
parkan profile image
Arkadiy Kukarkin

ok, I see the issue, the tsconfig I was inheriting from (node12) sets strict: true, which does not pass in this case

specifically, it seems that this fails because strict implies strictNullChecks, and given that this type is nullable it won't pass (if I cast it as { [name: string] : string } it's ok)