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
Allow programmers to more descriptively document the side effects of functions and have Typescript check against these descriptions. Google Closure seems to use this type of documentation for optimization. It could result in better self documenting code, more helpful tooling, and more logic errors caught.
I am fairly new to TypeScript so I'm not sure if this would be really helpful in practice or not. What do you think?
No side effects
/** @nosideeffects */functiona(){letfoo="asdf";foo="bar";returna}//OK, only local variables are assigned to/** @nosideeffects */functionb(){returnSOME_GLOBAL;}//OK, reads global state but does not modify it/** @nosideeffects */functionb(){SOME_GLOBAL="asdf";}//ERROR, non local variable assigned to/** @nosideeffects */functionc(bar: string){bar="123"returnbar}//OK, non-reference type argument modified/** @nosideeffects */functiond(bar: {a: string}){bar.a="123"}//ERROR, reference type argument modified/** @nosideeffects */functione(){constfoo=a();returnfoo}//OK, only @nosideeffects functions are calledfunctionf(){return"foo"}/** @nosideeffects */functiong(){constfoo=f();returnfoo}//ERROR, cannot call a normal function from a @nosideeffects function
Modifies
functiona(){letmyObj={foo: {bar: "bar"}}b(myObj)console.log(foo.bar)//WARN: myObj may have been clobbered by b(myObj)}/** @modifies {arg} */functionb(arg: any){deletearg.foo}
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Allow programmers to more descriptively document the side effects of functions and have Typescript check against these descriptions. Google Closure seems to use this type of documentation for optimization. It could result in better self documenting code, more helpful tooling, and more logic errors caught.
I am fairly new to TypeScript so I'm not sure if this would be really helpful in practice or not. What do you think?
No side effects
Modifies
The text was updated successfully, but these errors were encountered: