π 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.
π Search Terms
Pick, linter
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoHsAm7kG8BQyyYwYANhAFzIDOYUoA5gNyHKYQ0IMAOJ6IanQYgWbBOgC2PCpEzUARunQU4IVgF98+MAE8eKDNgAKUCADdgEAO7IAvMmPAEAawA8R9ABpkAIhLkEL7IAD5+EtKyEJi+AHys+BIgdOxwYHCUnvZ4bAEU1L4AwqogyFDKkr5e4lIyEHLU8GQ0ENVEHFy8-IK+AIwATADMVfgaCUkpYFjo1J6mFla2DphpcAlT2KwA9FvIAHoA-EA
π» Code
π 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.