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

feat[isRecordObjectOf]: checks own symbol key properties #110

Merged
merged 2 commits into from
Aug 10, 2024

Conversation

Milly
Copy link
Collaborator

@Milly Milly commented Aug 8, 2024

Contains bug fixes. See below comments.

@Milly Milly marked this pull request as draft August 8, 2024 19:39
@Milly
Copy link
Collaborator Author

Milly commented Aug 8, 2024

@lambdalisue
I have some questions regarding implementation.

isRecordObjectOf() and isRecordOf() walk the prototype chain of the target object and test all enumerable properties excluding Symbols.

Example:

class Foo {
  a = "a";
}
const foo = new Foo(); // foo has no own properties.
isRecordOf(is.String)(foo); // true
isRecordOf(is.Number)(foo); // false
  1. Is this the intended behavior?
  2. Should Symbols be tested up the prototype chain as well?

Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.05%. Comparing base (4ec8855) to head (27f86b1).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           symbol-properties-wip     #110   +/-   ##
======================================================
  Coverage                  98.04%   98.05%           
======================================================
  Files                         50       50           
  Lines                        817      821    +4     
  Branches                      88       89    +1     
======================================================
+ Hits                         801      805    +4     
  Misses                        16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lambdalisue
Copy link
Member

  1. Is this the intended behavior?

No. Because TypeScript's behavior is different

class Foo {
  a = "a";
}
const _foo: Record<PropertyKey, string> = new Foo();
const _bar: Record<PropertyKey, string> = { a: "a" };

CleanShot 2024-08-09 at 12 30 16

  1. Should Symbols be tested up the prototype chain as well?

Yes. Because TypeScript's behavior is so

const s = Symbol("symbol");
const _foo: Record<PropertyKey, string> = { a: "a", [s]: "b" };
const _bar: Record<PropertyKey, string> = { a: "a", [s]: 0 };

CleanShot 2024-08-09 at 12 32 18

@Milly
Copy link
Collaborator Author

Milly commented Aug 9, 2024

@lambdalisue
I expected the answers to 1 and 2 to be the same.
I wanted to know whether to implement both string keys and symbol keys by "checking only the own properties" (No, No) or by "following the prototype chain and checking everything" (Yes, Yes).

Isn't the second example like this?

const s = Symbol("s");
class Foo {
  [s] = "a";
}
const foo = new Foo();
isRecordOf(is.String)(foo); // true?
isRecordOf(is.Number)(foo); // false?

@Milly Milly force-pushed the symbol-properties/record-object-of branch from d025d34 to 27f86b1 Compare August 9, 2024 07:34
@Milly Milly changed the title WIP: feat[isRecordObjectOf]: implement symbol properties feat[isRecordObjectOf]: checks own symbol key properties Aug 9, 2024
@Milly
Copy link
Collaborator Author

Milly commented Aug 9, 2024

both string keys and symbol keys by "following the prototype chain and checking everything" (Yes, Yes).

I fixed this behavior like.

@Milly Milly marked this pull request as ready for review August 9, 2024 08:14
@Milly Milly requested a review from lambdalisue August 9, 2024 08:14
Copy link
Member

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Milly Milly merged commit 69bd020 into symbol-properties-wip Aug 10, 2024
6 checks passed
@Milly Milly deleted the symbol-properties/record-object-of branch August 10, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants