Closed zepumph closed 8 months ago
@marlitas, are you interested in this?
PropertyStateHandler unit tests are giving me some problems. This patch is passing tsc, but not QUnit, and I am not sure how to move forward. Requesting help from @zepumph when he has the chance.
@samreid helped me address the problems I was coming up against, and I can continue to move forward on the Axon conversion. Thanks @samreid! Un-assigning @zepumph until the rest is done and ready for review.
In TinyForwardingPropertyTests.ts I used a ts-expect-error
for this line:
myForwardingProperty.setTargetProperty( null, null, myDerivedProperty );
Without the ts-expect-error
I was receiving an error about DerivedProperty's setter being protected, and it made me wonder if that line is even allowed, and if it is why? @zepumph can you check that for me and provide some feedback?
You were definitely on to something. This is a weird one. Please read the doc and extra test I added above and let me know if you have any questions.
@zepumph that makes way more sense. Thanks for the clarification.
Onwards!
This is completed and ready for review. I left deprecated files as js
, as well as axon-phet-io-overrides, wasn't sure if that should be converted since it's a pre-load? Let me know if there's any additional work that should be done there.
Otherwise, assigning to @zepumph for review.
RE: https://github.com/phetsims/axon/commit/749cf4bedc4d60629a313286a7a0b2ab20f79696
true
, and not just any truthy, javascript-casted boolean (same with https://github.com/phetsims/axon/commit/749cf4bedc4d60629a313286a7a0b2ab20f79696):Subject: [PATCH] support multiple digits of major.minor versions, https://github.com/phetsims/phet-io-wrappers/issues/473
---
Index: js/TinyForwardingPropertyTests.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/TinyForwardingPropertyTests.ts b/js/TinyForwardingPropertyTests.ts
--- a/js/TinyForwardingPropertyTests.ts (revision 8a8debc476567daee8b1571b0a6df80eee1b678c)
+++ b/js/TinyForwardingPropertyTests.ts (date 1672765981026)
@@ -18,7 +18,7 @@
const myForwardingProperty = new TinyForwardingProperty<unknown>( true, false );
- assert.ok( myForwardingProperty.get(), 'basic value for Property' );
+ assert.ok( myForwardingProperty.get() === true, 'basic value for Property' );
const myTinyProperty = new TinyProperty( 'tinyProperty' );
myForwardingProperty.setTargetProperty( null, null, myTinyProperty );
<unknown>
is best here. I'd rather keep specific typing that works, rather than purposefully transform the Property type into a less-specific type in order to pass type checking. I think that new TinyForwardingProperty<boolean | string | number>
works best here.How about just passing in _.noop as the function?
Subject: [PATCH] support multiple digits of major.minor versions, https://github.com/phetsims/phet-io-wrappers/issues/473
---
Index: js/TinyEmitterTests.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/TinyEmitterTests.ts b/js/TinyEmitterTests.ts
--- a/js/TinyEmitterTests.ts (revision 8a8debc476567daee8b1571b0a6df80eee1b678c)
+++ b/js/TinyEmitterTests.ts (date 1672766395640)
@@ -32,7 +32,7 @@
e2.emit( '2, 2' );
e2.emit( undefined );
e2.emit( null );
- e2.emit( new TinyEmitter(), 7, () => { _.noop(); } );
+ e2.emit( new TinyEmitter(), 7, _.noop );
e2.emit( new TinyEmitter() );
} );
Thanks for all this great work!
@zepumph thanks for the review notes! I applied the changes to you described and also looked through the changes you added in PropertyStateHandler.
I do have a question with the PropertyStateHandler related to the benefits of generics vs. unknown. I saw you switched out many of the generics to be unknown and I thought that generics were safer overall, but perhaps I'm misunderstanding how they function. Let's find a time to chat after your honeymoon!
I saw the changes like converting
public unregisterOrderDependenciesForProperty<T>( property: ReadOnlyProperty<T> ): void {
const phetioIDToRemove = property.tandem.phetioID;
to
public unregisterOrderDependenciesForProperty( property: ReadOnlyProperty<unknown> ): void {
const phetioIDToRemove = property.tandem.phetioID;
In this case, the generic type parameter was providing no additional type checking or benefit, because it doesn't matter what the type parameter is. So it is clearer to say "unknown" so that it can accept any type. All of the public interface methods in PropertyStateHandler accept ReadOnlyProperty<IntentionalAny>
, and all of the private ones use ReadOnlyProperty<unknown>
since they are already any
by that point. The exception is public unregisterOrderDependenciesForProperty( property: ReadOnlyProperty<unknown> ): void {
but note it is local to that file only (careful, there are 2x of those methods, in different classes).
So I guess all of the ReadOnlyProperty<unknown>
in this file could be written as ReadOnlyProperty<IntentionalAny>
, but a rule of thumb is to prefer unknown
to IntentionalAny
where possible.
Met with @samreid to clarify some of my follow up questions from the above comment. I now have a much stronger understanding of generics and unknown, as well as the preferred use case for each. Thanks @samreid!
Closing this issue as completed.
Reopening because there is a TODO marked for this issue.
There are multiple tests and smaller files that are still in javascript. I would say we don't need to convert any files that are deprecated, like EnumerationDeprecatedProperty and its tests.