Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checker fails to report when combining Omit with & {[key: string]: unknown} #54214

Closed
kdeberk opened this issue May 11, 2023 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@kdeberk
Copy link

kdeberk commented May 11, 2023

Bug Report

πŸ”Ž Search Terms

omit type checker

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Omit

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Status = "created" | "canceled"

type StructA = {} & {[key: string]: unknown}

interface StructB extends StructA {
    status: Status
    version: number
    bar: string
}

interface StructC extends Omit<StructB, "bar"> {}

const x: StructC = {
    status: "cancelled",  // <- mistyped canceled
    version: "string"     // <- wrong type
}

πŸ™ Actual behavior

TS playground is not complaining about the two issues at the bottom. cancelled should be canceled and version should only accept numbers, not strings.

πŸ™‚ Expected behavior

TS playground should report about the two issues. In case of the cancelled<->canceled issue we're really relying on TS to catch these easy mistakes.

@jcalz
Copy link
Contributor

jcalz commented May 11, 2023

Duplicate of #50638

@MartinJohns
Copy link
Contributor

Also, be aware that indexer types with properties are never really type safe. Your type says any property has the type unknown, so you can assign any type to any property, including status and version.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 12, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants