-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
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
mirfilip, tskj, JakobBruenker, jkevingutierrez, eklenin and 1 moreniedzielski, DCzajkowski, tskj and JakobBruenker
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed