toss / use-funnel

A powerful and safe step-by-step state management library
https://use-funnel.slash.page
MIT License
192 stars 25 forks source link

[Feature]: Remove condition `K extends keyof TBase ? never : never` in CompareKeys Type #55

Closed L2HYUNN closed 1 month ago

L2HYUNN commented 1 month ago

Package Scope

@use-funnel/core

Description

Hello!

I’m very interested in the use funnel library, and while exploring the code to understand its internal structure, I came across the following code and had a few questions about it.

export type RequiredCompareKeys<TBase, TResult> = {
  [K in keyof TBase | keyof TResult]: K extends keyof TResult
    ? K extends keyof TBase
      ? TBase[K] extends TResult[K]
        ? never
        : K
      : undefined extends TResult[K]
        ? never
        : K
    : K extends keyof TBase
      ? never
      : never;
}[keyof TBase | keyof TResult];

It seems that the following line:

K extends keyof TBase ? never : never;

could be simplified to just never as shown below. Is there a specific reason for keeping this condition?

type RequiredCompareKeys<TBase, TResult> = {
  [K in keyof TBase | keyof TResult]: K extends keyof TResult
    ? K extends keyof TBase
      ? TBase[K] extends TResult[K]
        ? never
        : K
      : undefined extends TResult[K]
      ? never
      : K
    : never;
}[keyof TBase | keyof TResult];

If this simplification looks good to you, I’d be happy to open a PR.

Possible Solution

No response

etc.

No response

minuukang commented 1 month ago

Thanks to provide a type issue!

Is there a specific reason for keeping this condition?

The answer is no. that is a side effect typing at OptionalCompareKeys has missing condition of K extends keyof TBase ? K : never;, but RequiredCompareKeys doesn't need that.

it is remove and improve at #56 PR. and i will add you co-author at that PR.