Skip to content

Another narrowing bug with {} #18413

@chancancode

Description

@chancancode

TypeScript Version: playground

Code

type unknown = {} | undefined | null | void;

interface Dict {
  [key: string]: unknown;
}

function isDict(value: any): value is Dict {
  return value !== null && value !== undefined;
}

function any(): any {
}

let notSure: unknown = any();

if (isDict(notSure)) {
  notSure['foo']; // <- turn on strict mode to see error, `notSure` is `{}`
}

Expected behavior:

notSure is Dict after the narrowing

Actual behavior:

notSure is {} after the narrowing

Playground link

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions