-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
General Type Maintenance #8462
General Type Maintenance #8462
Conversation
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.
Yay, this is awesome!
template: Template | any, | ||
[head, ...tail]: Array<string>, | ||
): any => { | ||
const getPath = (template: Template, [head, ...tail]: Array<string>): any => { |
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.
any way to have it not return any
? unknown
is preferred
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.
shouldn't it return Template | undefined
?
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.
I will update this with an overload to return the actual nested type, and unknown if it cant determine. I will overload up to 5 nested levels.
const test2 = getPath({a: {b: 2}}, ['a']); // return type:{b:number}
const test3 = getPath({a: {b: 2}}, ['a', 'b']); // return type:number
const test4 = getPath({a: {b: 2}}, ['a', 'bc']); // return type:unknown
const test5 = getPath({}, ['a']); // return type:unknown
@@ -176,7 +176,7 @@ export function printObjectProperties( | |||
printer: Printer, | |||
): string { | |||
let result = ''; | |||
const keys = getKeysOfEnumerableProperties(val); | |||
const keys = getKeysOfEnumerableProperties(val) as Array<string>; |
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.
does this need to be casted, provided that it's already done in line 22? Maybe declaring the return type for getKeysOfEnumerableProperties
would help
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.
Whoops first added it here, then decided to change it in getKeysOfEnumerableProperties, and forgot to take this one off. Thanks!, BTW- this functions is duplicated a few times throughout, maybe we should move this in jest-utils
in different PR?
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.
nice cleanup!
Co-Authored-By: Simen Bekkhus <sbekkhus91@gmail.com>
…ein/jest into general-type-cleanup
Codecov Report
@@ Coverage Diff @@
## master #8462 +/- ##
==========================================
- Coverage 62.32% 62.31% -0.01%
==========================================
Files 266 266
Lines 10735 10735
Branches 2614 2617 +3
==========================================
- Hits 6691 6690 -1
Misses 3460 3460
- Partials 584 585 +1
Continue to review full report at Codecov.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
As part of #8436 , this PR has a much larger scope, targeting obvious unnecessary castings and consistent Object Literal Types throughout the codebase.
For consistency I decided to use
Record<string,string>
if the type didnt have a meaningful index key ie:Test plan