Skip to content

Mistake in the docs #57005

Open
Open
@m-Pawlowicz

Description

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

Hi guys, correct me if im wrong, but i believe the docs for satisfies keyword have an error

type Colors = "red" | "green" | "blue";
type RGB = [red: number, green: number, blue: number];
const palette: Record<Colors, string | RGB> = {
    red: [255, 0, 0],
    green: "#00ff00",
    bleu: [0, 0, 255]
//  ~~~~ The typo is now correctly detected
};
// But we now have an undesirable error here - 'palette.red' "could" be a string.
const redComponent = palette.red.at(0);

since values are unions of string and array, palette.red.at(0) will not throw an error, because at method is a method that exists for both types.
Cheers :).

image

Metadata

Assignees

No one assigned

    Labels

    DocsThe issue relates to how you learn TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions