We work with Svelte, tailwindcss, & TypeScript for our front-end; then C# for our back-end.
- Use
PascalCasefor non-route svelte files. - Use
camelCasefor TS files. - Use
kabob-namesfor URL paths.
Include the lang="ts" attribute onto your script starting tags of .svelte files.
For readability, order the contents of your script section by the order of:
- imports
- exports
- types
- consts
- lets
- $:
- event handlers (onMount, etc.)
- functions
- Use
PascalCasefor class and type names. - Use
camelCasefor method and variable names. - For the propeties of a class, public properties should adhere to
camelCaseand private properies should adhere to_underscoreCamelCase. - Unlike C#, don't add the
Asyncsuffix to TypeScript methods.
In the same way var is used in C# (don't use var in TypeScript) to reduce redundant code, if your let or const declaration assigns a value with a clear type, then you don't need to specify the type.
let x = 0; // ": number" not required in this case. When going communicating between the front-end and back-end, the name of the class and function should match. Use an ActionObject/action-object approach for naming these.
public class GetGithubAccounts : FunctionBase
{
public GetGithubAccounts(ILogger<GetGithubAccounts> logger) : base(logger) { }
[Function("get-github-accounts")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData requestData)
{
// ...
}
}