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
All filenames are written in snakecase style. In the file name, letters from lower case a-z and _ are allowed. Use numbers 0-9 only if it is necessary. For example, if the function is called encodeBase64.
The filename would look like this:
encode_base64.ts
Foldername
In the folder name, letters from lower case a-z and _ are allowed. Never use numbers to sort folders. For example, 01_help, 02_error, 03_components, ...
Filecontent
A file should have only one main function/class which is exported. The function/class should then be named exactly like the file name, in camelcase. If you have an object that mimics an enum then the associated type of this object will be exported as well. You can read more about this in the enum section.
For example, if we want to write a function that reads a text file, we would name the file read_text_file.ts. In the file we would then export a function which looks like this.
Function name readTextFile() becomes Filename read_text_file.ts.
Helpers/Untilities
Helper functions/objects for the main function that gets exportet are allowed. It is also allowed to export an object and a type as long as the type is created from the object. You can look up the reason for this under enum.
Vertical character limit
A file may contain a maximum of 30 lines of code (excluding comments and whitespace between lines). This is for increasing readability. If the number of lines or the number of indentations is exceeded, then the code must be refactored to separate files. This rule does not apply to data structures as for example json files.
Horizontal character limit
The maximum character limit for a line is 120 characters and a maximum of 4 indentations.
Documentation/Comments
All TypeScript files are documented in the JSDoc format.
Variables/Types
All variables are written in camelcase. You can read more about that in the let/const/var section.
constgreeting='Hello World';letage : number;
Spaces are inserted between a variable and the colon and between the colon and a type.
letword : string;
When a value is assigned to a variable in an object, no space is inserted between the variable and the colon. This is to distinguish a direct type assignment from a value assignment.
constobject={key: 'Text'};
Declaration-Statements
let/const/var
let/const names are written in camelcase. The same is applied to members of objects. Avoid the use of var, use let/const instead.
constmessageVariants={greetingMessage: 'Hey, nice to see you.'}
If the object has more than one key or the key name exceeds the maximum character limit for a line then the line needs to be wrapped.
constmessageVariants={greetingMessage: 'Hey, nice to see you.',goodbyeMessage: 'Bye!'}
If you declare a variable whose content does not change, then this variable is written in ALL_CAPS. This rule does not apply to objects described in other structures, like "enum like objects" in the enum section.
constAPI_ENDPOINT='https://api.example.com';
interface
Interface names are started with a capital letter. The rest of the name is written in camelcase. Also known as PascalCase. Variable definitions are separated by a comma. Each key in an interface needs to be on a separate line.
interfaceFooBar{text : string,value : number}
type
...
enum
Enum names are written in camelcase. Enum variables are written in all caps. Each key in an enum needs to be on a separate line.
enumtextTypes{TEXT_A,TEXT_B}
Avoid using enums as presets for default values. Use enum like objects instead. Always export these objects as const.
Function names are written in camelcase. If the function has more than one parameter or the parameter name exceeds the maximum character limit for a line then the line needs to be wrapped. The same rule also applies to the content of the function. Always specify a return value for the function. The return value is specified in the same form as for a type.
Named functions
No space is inserted between the function name and the parentheses. A space is inserted between the return type and the curly brackets.