declare let obj: {prop: string | null} | undefined;
let a = obj?.prop!; // not allowed: 'a' is inferred as 'string' instead of 'string | undefined'
let b = obj?.prop!.length; // allowed to asssert that a certain property in the chain is not nullish, 'b' is 'number | undefined' as expected
NonNull inside an optional chain is treated special and only asserts that one element in the chain is non-null. Whereas NonNull at the end of an optional chain removes null and undefined from the type of the whole chain. That doesn't make any sense because you wouldn't need an optional chain if you knew everything is non-null.
NonNull inside an optional chain is treated special and only asserts that one element in the chain is non-null. Whereas NonNull at the end of an optional chain removes null and undefined from the type of the whole chain. That doesn't make any sense because you wouldn't need an optional chain if you knew everything is non-null.