Closed pixelzoom closed 1 year ago
Over in https://github.com/phetsims/chipper/issues/1224 I deleted that @returns
to enabled a bad-typescript-text rule. Wouldn't we still want to use typescript in this case?
Type GetRay = ( x: RayTypeEnum | null ) => LightRayType;
const getRay: GetRay = . . . . .
No. getRay
returns a LightRay in one case, a partial implementation of LightRay (duck type) in another.
This seems to work (uncommitted):
type LightRayDuckType = {
getAngle: () => number;
powerFraction: number;
};
const MOCK_ZERO_RAY: LightRayDuckType = {
getAngle: () => 0,
powerFraction: 0
};
const getRay = ( type: RayTypeEnum | null ): LightRayDuckType => {
...
};
Sounds good. However you want to type it. I wasn't trying to recommend the typescript code. I was trying to mention that having @returns
in this case will be a lint error, and we should use typescript to accomplish this.
I added a type alias and specified it as the returned type. Closing.
Discoverd while working on
In AngleNode.ts:
@returns {LightRay}
is incorrect,MOCK_ZERO_RAY
is not a LightRay instance. It's a duck type:So the
@returns
cannot be properly replaced with a return type.Not sure how you'd like to address this, so assigning to @samreid.