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

OverrideProperties and Merge don't retain callable aspect of type #969

Open
TomerAberbach opened this issue Oct 19, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@TomerAberbach
Copy link
Contributor

TomerAberbach commented Oct 19, 2024

@TomerAberbach TomerAberbach added the bug Something isn't working label Oct 19, 2024
@TomerAberbach
Copy link
Contributor Author

Was playing around with using this trick to retain the callable type, but it doesn't retain generic type parameters if the function is generic

@sindresorhus
Copy link
Owner

// @nidomiro @jinta4020

@TomerAberbach
Copy link
Contributor Author

I think this is the most related TypeScript comment/issue

microsoft/TypeScript#53760 (comment)

@nidomiro
Copy link
Contributor

This is a really tricky one. I'm not sure if we can do anything here right now.
Even Omit itself will remove the callable aspect of the type: https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnA3nA8gNxVKYAExQAUoJVZgUBnAGjgFl8BzNAXzgDMKQ4A5ElQBabnRgCAsAChZwtAGEAhgBtVygEaqUAdWAwAFuUr4kcALwZZASAAUASgBccHBGK2wFKkhcA7AFcQTXxZDnlkNCwQAxgUIktsGJgAHhV1LR19IxMfREYBL1NYRAEAPlk4KrgAehq4AD0AflkSAGMNKDQ2iD9aeAhkuKIXaNj42Tq4AGVDCADVBJC4NrUNbRRGTQD4Vgh4ZT84fAooWUHxokdZIA

Maybe you can work around this one, with something like this:

import type { OverrideProperties, Merge } from 'type-fest'

type MyCallable = {
	(): void
}

type CallableWithProperty = MyCallable & {
	property: number
}

type Overridden = OverrideProperties<CallableWithProperty, { property: string }> & MyCallable
declare const overridden: Overridden
overridden()

type Merged = Merge<CallableWithProperty, { property2: string }> & MyCallable
declare const merged: Merged
merged()

(https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnA3nA8gNxVKYAExQAUoJVZgUBnAGjgFl8BzNAXzgDMKQ4A5ElQBabnRgCAsAChZwtE0QBhAIYAbdaoBG6tAF4MsgJAAKAJQAuODgjFZHWfORo1mnXoDqwGAAtylPhIcIZKblq6aABkRjLGYBRUSNYAdgCuINr4Dk4yCth4BMQkKSEF+IQkAUk0tAA84R4o3n7VQYiMmAmBsIjWtDCEKaxwHAB8cDFhGhF6snALcAD0S3AAegD8siQAxlpQaDsQKQNwEIWVJda4FcUoKbLnt0QlFrn5LFDsRGWf7A0zJotfyJdqdODdJKIABM-UGwGGowmUxUgMi80WK3WWxku32h2OpxAbBQRGsf1JsmJX1JbxkQA)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants