You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classImmutable{getprop(): string{return'foo';}}classMutable{setprop(value: string){}}classOther{getprop2(): string{return'foo';}}consttest=(v: Mutable)=>{};test(newOther());//Compile error as expectedtest(newImmutable());//No error, but would also expect one
π Actual behavior
Other correctly causes a compile error as it does not have prop property. Immutable passes compiler check even though the prop property is read-only (just a get)
π Expected behavior
I would expect both Other and Immutable to fail the typing of test as neither adhere to the structure of Mutable.
If inside test I try and set v.prop when Immutable is passed in I get a runtime error. I would expect the typing to guard against this.
The text was updated successfully, but these errors were encountered:
The other issue is the absence of a writeonly modifier to model properties with setters but no getters. For example, this would ideally be a compile-time error:
constx={setfoo(_x: string){}}x.foo='ok'// should be allowedx.foo.includes('yikes')// should not be allowed
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Other
correctly causes a compile error as it does not haveprop
property.Immutable
passes compiler check even though theprop
property is read-only (just aget
)π Expected behavior
I would expect both
Other
andImmutable
to fail the typing oftest
as neither adhere to the structure ofMutable
.If inside
test
I try and setv.prop
whenImmutable
is passed in I get a runtime error. I would expect the typing to guard against this.The text was updated successfully, but these errors were encountered: