TypeScript - Use PascalCasing or camelCasing for module names?

I am wondering if I should use PascalCasing or camelCasing for my module names, so far I have always used PascalCasing, Ayolan.Engine.Rendering .: Ayolan.Engine.Rendering instead of Ayolan.Engine.Rendering (I save PascalCasing for the container, since I want the name the global object was Ayolan , not Ayolan ).

I did not find any headers, found thread from 3 years ago, but not very useful.

I am interested because I work with Java developers and it makes sense to use camelCasing for them, but this is not what I have seen so far with TS.

+6
source share
2 answers

In TypeScript, we use the same standards as JavaScript, because we work with many JavaScript libraries (and possibly also consume JavaScript code).

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

 module ExampleModule { export class ExampleClass { public exampleProperty: string; public exampleMethod() { } } } 

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

You will notice that this works well with the following code:

 Math.ceil(Math.PI); 

Most importantly, stick to the style you are using, as the style can mean meaning, so if you are incompatible, it will cause confusion.

+7
source

Note. Internal modules are namespaces. The next version of TypeScript focuses on plug-ins from ECMAScript 6 that are not namespaces.

Microsoft has not published a naming guide for internal modules in TypeScript.

Arguments for PascalCase

The internal module is similar to a class with only static elements:

 module MyLib { export function f1() { } export function f2() { } // ... } 

Languages ​​that use the pascal case for namespaces: C # , PHP .

Arguments for CamelCase

The name in the camel case resembles the Google Style Guide for JSON :

Property names must be anchored to camel, ascii strings.

... but the internal module is not a JSON object.

Languages ​​that use camel case for namespaces :? (Not Java, which uses lowercase letters).

+1
source

Source: https://habr.com/ru/post/985051/


All Articles