Help getting user input from a text field

I feel like I’m overlooking something obvious here. Why does this result in a null value, and how can I fix it to return the entered value?

var titleInput = new Alert()
titleInput.title = "Input:"
titleInput.addTextField("Title")

let title = await titleInput.presentAlert()

console.log(titleInput.textFieldValue(0))

Thanks.

Worked for me after typing in “abc”.

Are you pressing return at the end or selecting cancel?