-
-
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
refactor(jest-mock): simplify PropertyLikeKeys
utility type
#13020
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,10 +86,10 @@ type IndexObject = { | |
|
||
methodA(): void; | ||
methodB(b: string): boolean; | ||
methodC: (c: number) => true; | ||
methodC: (c: number) => boolean; | ||
|
||
propertyA: {a: 123}; | ||
propertyB: {b: 'value'}; | ||
propertyA: {a: number}; | ||
propertyB: {b: string}; | ||
}; | ||
|
||
// ClassLike | ||
|
@@ -142,6 +142,6 @@ declare const objectProperties: PropertyLikeKeys<SomeObject>; | |
declare const indexObjectProperties: PropertyLikeKeys<IndexObject>; | ||
|
||
expectType<'propertyA' | 'propertyB' | 'propertyC'>(classProperties); | ||
expectType<string>(indexClassProperties); | ||
expectType<string | number>(indexClassProperties); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fells like A note from TS docs: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checked, TypeScript allows this: type IndexObject = {
[key: string]: Record<string, any>;
};
const indexObject: IndexObject = {
123: {a: 123},
prop: {b: 'abc'},
}; So it feels like this is correct (or?): type IndexObject = {
[key: string]: Record<string, any>;
};
type PropKeys = PropertyLikeKeys<IndexObject>; // `string | number` |
||
expectType<'propertyA' | 'propertyB' | 'someClassInstance'>(objectProperties); | ||
expectType<string>(indexObjectProperties); | ||
expectType<string | number>(indexObjectProperties); |
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.
Same test is repeating few lines bellow.