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
{{ message }}
Repository navigation
Suggestion: Add readonly references to objects & mark readonlyThis methods (pure functions)Β #42758
Have a way to check readonly object references (including parameters, and this parameter). That allows to check than a function does not modifys an object.
π Motivating Example
classFigure{constructor(publicname: string){}checkName(){this.name+=' !'}readonlyMethodlogAccess(){console.log('one instance of Figure was accesed');}readonlyMethodsafeCheck(){// @ts-expect-errorthis.name+=' x'// this is readonly in a readonlyMethod context}}functionshowRO(figure: readonlyReferenceFigure){console.log(figure.name);// @ts-expect-errorfigure.name+=" x";// if figure is a readonly reference you can use it to modify the object// @ts-expect-errorfigure.checkName();// if figure is a readonly reference you can use it to modify the object calling a methodfigure.logAccess();// ok logAccess is a readonly method}varx=newFigure('triangle');showRO(x);varz: readonlyReferenceFigure=x;// ok, you can assign a writeable object to a readonlyReference// @ts-expect-errorvary: Figure=z;// you cannot do the oposite.
π» Use Cases
Actually I'am ussing Readonly aproach, but it not contemplates all cases.
Activity