Closed
Description
Bug Report
Apologies if this is a duplicate, but I wasn't able to find anything.
π Search Terms
noUncheckedIndexedAccess property in object
β― Playground Link
π» Code
declare function invariant(condition: boolean): asserts condition;
function foo(obj: Readonly<Record<string, string>>) {
invariant(obj && "test" in obj);
// this one below does narrow to `string`
// invariant(!!obj["test"]);
const x = obj["test"] // string | undefined but should be string
}
π Actual behavior
x
is typed as string | undefined
π Expected behavior
x
should be typed as string