Skip to content

Omit should throw error if not existing key try to remove #40262

Closed
@pahuta

Description

@pahuta

Search Terms

Omit inexistent key

Suggestion

Let's consider next code where we omit inexistent key from interface Todo :

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

type TodoPreview = Omit<Todo, 'not_existed_key'>; // currently error is not thrown

Use Cases

Let's imagine that previously interface Todo had property not_existed_key and we had variable such as

const todoItem: TodoPreview = {...}

but then not_existed_key was removed and developer forgot to remove TodoPreview because it became redundant.

Examples

From my point of view will be better to have more strictly behavior of Omit.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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