This project is read-only.

With keyword

Topics: Language Specification
Oct 20, 2013 at 12:27 PM
Edited Oct 20, 2013 at 8:34 PM
EDIT: to be more clear I am asking for this feature to be introduced in typescript.

We are building a library for typescript. It is intended for non-programmers and the users will spend most of the time setting properties and calling parametrized methods from the library.

(A version of the library was Previously done in VBA). There With keyword usage was something very easy for users to understand and improved code readability/understandability a lot.

Will something like below be possible in TypeScript?

With class{
.property = 123;
.MethodA (parameter);
.MethodB (parameter);
globalVariable = .ReadResult();
Oct 20, 2013 at 7:03 PM
No, there is no "with" keyword and nothing like it.

I'm not at all sure TypeScript is the best language for non-programmers to be using, since it is essentially a slightly-more-complicated version of JavaScript, which is itself a pretty complicated language.

Sent from Mailbox for iPad
Oct 20, 2013 at 8:33 PM
Maybe I should have put it another way, more clearer this time... will there be any support for a with keyword? I found it extremely useful on vba. All the non-programmers loved it because it was so spoken language like, improved readability and save a lot of typing.

Side Note: As for typescript being hard on non programers... In my particular case the users will set some values to the custom library members and call some functions with parameters. That's all.
Oct 21, 2013 at 7:34 PM
JavaScript, and thus TypeScript, already has a 'with' statement but it generally leads to pain ( In TypeScript if you use a 'with' statement then anything within it will be resolved to type 'any' and you will lose a lot of the nice typechecking the language provides. You could instead use a simple var or import alias to shorten names where applicable, but you won't have the same syntax with a name preceded by a dot.

As far as I can tell the VBA syntax is barely any different from using a normal constructor but with named arguments (which TypeScript does not support), though even without them the Visual Studio completion help will fill in the blanks similarly as far as parameter names go.