-
-
Notifications
You must be signed in to change notification settings - Fork 662
improve Simplify type
#1277
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
base: main
Are you sure you want to change the base?
improve Simplify type
#1277
Conversation
449bcea to
2d4c1ba
Compare
…ion/classes - Added `ExtractCallSignature` type to extract call signatures from function types. - Moved `HasMultipleCallSignatures` type to `internal/function.d.ts`. - Updated `SetOptional`, `SetReadonly`, and `SetRequired` types to utilize `ExtractCallSignature`. - Updated tests to reflect changes in type behavior and ensure correctness.
2d4c1ba to
aeb2ff8
Compare
|
One thing to note is that when passing a function, the resulting type becomes This seems to be the best solution so far, at least until we find a proper fix for |
som-sm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the PR has some unintended formatting changes, can you please go through the PR once and clean it up.
som-sm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from MergeDeep and a couple of test cases does anything else break if we simply add a Function check in Simplify? Like:
- export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
+ export type Simplify<T> = T extends Function ? T : {[KeyType in keyof T]: T[KeyType]};It'd be nice if we could keep the implementation simple. The test cases should be easily fixable. So, if it's just MergeDeep, then it'd be better if we could somehow fix MergeDeep itself.
| ? IsUnknown<This> extends true // TODO: replace with `FunctionWithMaybeThisParameter` | ||
| ? (...args: Parameters) => Return | ||
| : (this: This, ...args: Parameters) => Return | ||
| : unknown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning unknown for non-functions doesn't seem correct in general. It shouldn't be designed just for the specific use case in Simplify (ExtractCallSignature<Type> & _Simplify<Type>).
Simplifytype to improve flattening and support of union/function/classesExtractCallSignatureinternal type to extract call signatures from function types.HasMultipleCallSignaturesinternal type tointernal/function.d.ts.SetOptional,SetReadonly, andSetRequiredtypes to utilizeExtractCallSignatureandSimplify.