phetsims / axon

Axon provides powerful and concise models for interactive simulations, based on observable Properties and related patterns.
MIT License
10 stars 8 forks source link

Property<true> is not assignable to type Property<boolean> #381

Closed pixelzoom closed 2 years ago

pixelzoom commented 2 years ago

This seems wrong.

class Foo {

  readonly isActiveProperty: Property<boolean>;

  constructor() {

    // TS2322: Type 'Property<true>' is not assignable to type 'Property<boolean>'.
    this.isActiveProperty = new Property( true );
  }
}
pixelzoom commented 2 years ago

I guess TypeScript is inferring that Property(true) is a Property whose only possible value is true. So I would need to instantiate as:

this.isActiveProperty = new Property<boolean>( true );

Do I understand that correctly?

samreid commented 2 years ago

There must be some other ingredient at play here, since just instantiating new Property(true) infers type Property<boolean>:

image

But without understanding that nuance, yes, I think either new Property<boolean>( true ); or new BooleanProperty( true ); would be good.