TypeScript - Use PascalCasing or camelCasing for module names?

Vadorequest picture Vadorequest · Apr 13, 2015 · Viewed 18.9k times · Source

I'm wondering if I should use PascalCasing or camelCasing for my modules names, so far I've always used PascalCasing, i.e: Ayolan.Engine.Rendering instead of Ayolan.engine.rendering (I keep PascalCasing for the container, since I want the global object name to be Ayolan and not ayolan).

I haven't found any headline on this, found that thread from 3 years ago but not really useful.

I'm wondering because I'm working with Java developpers and to them it makes more sense to use camelCasing, but that's not what I've seen so far with TS.

Answer

Fenton picture Fenton · Apr 13, 2015

In TypeScript, we use the same standards as JavaScript, because we are working with many JavaScript libraries (and potentially being consumed by JavaScript code too).

So we prefer PascalCase for modules and classes, with members being camelCase.

module ExampleModule {
    export class ExampleClass {
        public exampleProperty: string;

        public exampleMethod() {

        }
    }
}

The only other style rule I can think of is that constants are ALL_UPPER.

You will notice that this blends in nicely with the following code:

Math.ceil(Math.PI);

Most importantly of all - keep consistent with the style you use as the style can imply meaning, so if you aren't consistent it will cause confusion.