Skip to content

Pick doesn't validate correctlyΒ #55735

Closed
Closed
@guohaolay

Description

@guohaolay

πŸ”Ž Search Terms

Pick, linter

πŸ•— Version & Regression Information

  • This is the behavior in version 4.0.7, and whatever the TypeScript playground uses

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoHsAm7kG8BQyyYwYANhAFzIDOYUoA5gNyHKYQ0IMAOJ6IanQYgWbBOgC2PCpEzUARunQU4IVgF98+MAE8eKDNgAKUCADdgEAO7IAvMmPAEAawA8R9ABpkAIhLkEL7IAD5+EtKyEJi+AHys+BIgdOxwYHCUnvZ4bAEU1L4AwqogyFDKkr5e4lIyEHLU8GQ0ENVEHFy8-IK+AIwATADMVfgaCUkpYFjo1J6mFla2DphpcAlT2KwA9FvIAHoA-EA

πŸ’» Code

interface Todo {
  title: string;
  description: string;
  completed: boolean;
}

type TodoPreview = Pick<Todo, "title" | "completed">;

const data:Todo = {
  title: "Clean room",
  completed: false,
  description:"123",
};

// TypeScript correctly identifies the extra key `description`:
const todo: TodoPreview = {
  title: "Clean room",
  completed: false,
  description:"123",
};

// But doesn't pick up if assigned this way:
const todo2: TodoPreview = data;

πŸ™ Actual behavior

No error reported

πŸ™‚ Expected behavior

Error should be reported

Additional information about the issue

Pick does not validate correctly if using an object with more keys than the Picked key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions