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
These are a series of recommendations for developing code in this repository. Not all existing code will comply
67
+
with these guidelines, but new code should unless there are specific reasons not to.
68
+
69
+
While we develop code in TypeScript we generally want to aim for the compiled JavaScript to not be substantially different than if it had been written as JavaScript.
70
+
71
+
### Avoid using TypeScript enumerations. Instead use unions of strings.
While we are using TypeScript not all consumers of our code will be. Using a TypeScript enum from JavaScript is not very ergonomic.
90
+
Additionally the code size associated with enums is going to be larger. The enum actually generates code, where the union provides type safety, but has no impact on the generated code.
91
+
92
+
### Prefer interfaces over classes when reasonable, especially if publicly exposed.
function createMyData(value:string, another:string, mutable:string):MyData {
111
+
return {
112
+
value,
113
+
another,
114
+
mutable
115
+
}
116
+
}
117
+
```
118
+
119
+
There are several potential problems using classes and some of them may be unexpected.
120
+
121
+
Classes produce JavaScript code while interfaces only represent contracts and don't exist in the generated JavaScript. In client-side applications keeping size to a minimum is very important.
122
+
123
+
The minification of associated functions is also another major difference. Functions that are not exported from the package can have their names minified. Methods that are part of a class are generally not minified.
124
+
125
+
A number of classes are present in the SDKs that cannot be removed without a major version. In order to reduce the size of these classes we have added support for minification of any member that starts with an underscore.
126
+
127
+
Another thing to remember is that the private and readonly only really affect TypeScript. Using JavaScript you can still access and mutate. Our minification of private members starting with an underscore also helps prevent unintentional usage from JavaScript.
0 commit comments