This is my code:
export const newPost = functions.firestore
.document(\'post/{postId}/\')
.onCreate((snap, context) => {
const postData = snap.data()
A bit hacky, but a quick fix const postData: any = snap.data()
Your TypeScript configuration almost certainly has strict type checking enabled, which will give you this warning when you try to access properties of something that could be null or undefined. Check your tsconfig.json and look for "strict": true"
in the compiler options. The TypeScript bindings for the DataSnapshot.data() API says that the return value of data() could anything (including null or undefined), and TypeScript is forcing you to deal with this fact correctly at compile time so that your code doesn't crash at runtime.
The sample code you're looking at is plain JavaScript, which does not have any type checking. It is assuming that the snapshot will not be null or undefined. If you found this to be confusing or problematic, please use the "send feedback" link at the top of the page of documentation to explain what was confusing to you.