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

internalise private stuff, fixing dual types incompatibility #4842

Merged
merged 8 commits into from Mar 28, 2024

Conversation

patroza
Copy link
Contributor

@patroza patroza commented Mar 27, 2024

fixes #4519, #4354

@patroza patroza requested a review from dubzzz as a code owner March 27, 2024 16:12
Copy link

codesandbox-ci bot commented Mar 27, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2c67201:

Sandbox Source
@fast-check/examples Configuration

@dubzzz
Copy link
Owner

dubzzz commented Mar 27, 2024

Thanks for the help, let's see if it passes the CI 🤞

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.49%. Comparing base (141571b) to head (2c67201).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4842   +/-   ##
=======================================
  Coverage   93.49%   93.49%           
=======================================
  Files         207      207           
  Lines        5015     5015           
  Branches     1368     1326   -42     
=======================================
  Hits         4689     4689           
  Misses        326      326           
Flag Coverage Δ
unit-tests 93.49% <100.00%> (ø)
unit-tests-18.x-Linux 93.49% <100.00%> (ø)
unit-tests-20.x-Linux 93.49% <100.00%> (ø)
unit-tests-latest-Linux 93.49% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

.yarn/versions/1488efe6.yml Outdated Show resolved Hide resolved
@@ -18,6 +18,7 @@ export class Value<T> {
*/
readonly hasToBeCloned: boolean;
/**
* @internal
Copy link
Owner

Choose a reason for hiding this comment

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

This one seems to be on an unrelated field? 🤔

Copy link
Contributor Author

@patroza patroza Mar 27, 2024

Choose a reason for hiding this comment

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

any private field of an exported class, or symbol on an exported interface makes the types incompatible

@patroza
Copy link
Contributor Author

patroza commented Mar 27, 2024

DepthIdentifier is a useless public type now because it's only member, the symbol is now internal.
Is this type important to be public and exported? An alternative could be a string literal.

@patroza
Copy link
Contributor Author

patroza commented Mar 27, 2024

Looks like all pass except doc publishing due to no permission

@dubzzz
Copy link
Owner

dubzzz commented Mar 27, 2024

Seems green ✅

I'll just checkout the resulting package tomorrow morning to see how it behaves

@@ -4,7 +4,9 @@
* @public
*/
export class PreconditionFailure extends Error {
/** @internal */
private static readonly SharedFootPrint: symbol = Symbol('fast-check/PreconditionFailure');
Copy link
Owner

Choose a reason for hiding this comment

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

Probably worth changing it into a Symbol.for so that we make sure that CJS and MJS world can interoperate between each others.

Copy link
Contributor Author

@patroza patroza Mar 28, 2024

Choose a reason for hiding this comment

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

sadly Symbol.for is also no type fix;

const a = Symbol.for("a")
const b = Symbol.for("a")
const c = (_: typeof b) => 1

c(a)
//^ Argument of type 'typeof a' is not assignable to parameter of type 'typeof b'.

Copy link
Owner

Choose a reason for hiding this comment

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

Definitely! Not asking to drop the @internal, just asking to switch from Symbol to Symbol.for so that CJS entities could be consumed by MJS ones... And it will be better aligned with typings that just tell: don't care for symbols (for external users).

I'm wondering if this one would be an issue for you too: export const cloneMethod = Symbol('fast-check/cloneMethod');. I'm mostly thinking about export function hasCloneMethod<T>(instance: T | WithCloneMethod<T>): instance is WithCloneMethod<T>, if we apply your trick users will see a method like export function hasCloneMethod<T>(instance: T): instance is T and their code will refuse to access the symbol, no? 🤔

Well if you don't have to change cloneMethod then the problem right above does not exist 😄

Maybe I can deal with Symbol.for in a separate PR as it might breaks other things 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea separate would be great.
the current implementation is tested and works in the @effect/schema case

Copy link
Owner

Choose a reason for hiding this comment

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

Ok perfect! If the current change is enough to patch all the problem you faced then we can probably go with it. I'll just run a last manual set of tests on it but it should be ok. And I'm still in between patch or minor, but patch seems ok as we mostly make the typings relaxed on something probably not used that much 🤔

@dubzzz
Copy link
Owner

dubzzz commented Mar 28, 2024

DepthIdentifier is a useless public type now because it's only member, the symbol is now internal.
Is this type important to be public and exported? An alternative could be a string literal.

Useless for now 😢 I hope to put it back once I can move back to full ESM. Hope that recent changes around CJS-MJS interrupt will help me to only ship ESM version in a few years... At that point in time I might re-enable that opaque type. For now it only helps me internally and may still be useful for users so that they reference the future opaque type in their typings (even if, nothing is opaque in it 😂).

@dubzzz dubzzz merged commit 2e675d9 into dubzzz:main Mar 28, 2024
68 of 69 checks passed
@dubzzz
Copy link
Owner

dubzzz commented Mar 28, 2024

🚀 It's live on 3.17.1

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.

Problem when mixing local project moduleResolution nodenext and a 3rd party package using fast-check
2 participants