You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const throwParseError = (def: unknown): never => {
throw new Error(`${def} is not a valid definition`)
}
class Foo {
// Property 'bar' has no initializer and is not definitely assigned in the constructor.(2564)
bar: string
constructor(def: string | null) {
if (def === null) {
// this return pattern is useful for narrowing
// if you remove `return` here, the initialization error goes away
// but the assignment to bar is then an error
return throwParseError(null)
}
this.bar = def
}
}
π Actual behavior
TypeScript reports that Property 'bar' has no initializer and is not definitely assigned in the constructor.(2564)
π Expected behavior
TypeScript should identify that in every viable branch of the constructor, bar is assigned.