Closed
Description
openedon Jan 30, 2019
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms: Object undefined
Code turn strictNullChecks
on
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
type EventType = 'click' | 'dblclick'
const handlerMap: { [P in EventType]?: any[] } = {}
function addHandler<P extends EventType>(evType: P) {
const handlerList = handlerMap[evType] || []
handlerList.push({}) // Error here: Object is possibly 'undefined'
handlerMap[evType] = handlerList
}
Expected behavior: No Error
Actual behavior: Shows Error
Related Issues:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment