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
Copy file name to clipboardExpand all lines: docs/standards/development_language_standards.md
+46-4Lines changed: 46 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,11 +71,49 @@ application performance in most Web-facing scenarios.
71
71
This can be seen across government as well, in particular the GDS front end community tend to publish their products
72
72
so that they can be easily used in Ruby and Node.js, in particular.
73
73
74
-
## We use JavaScript as our Node.js development language
75
-
We do not use TypeScript (or any other extensions to the JavaScript language).
74
+
## We use JavaScript as our primary Node.js development language
75
+
Teams should always look to use vanilla JavaScript in the first instance.
76
76
77
-
For the types of digital services we build, TypeScript is unneccessary as any benefits don't outweigh the overhead.
78
-
Use vanilla JavaScript.
77
+
A Typical Defra digital service is a simple transactional application that does not require complex type
78
+
structures.
79
+
80
+
For rarer scenarios where JavaScript alone has evidence of not being sufficient for the use case, then [JSDoc](https://jsdoc.app/) should be used to provide type annotations.
81
+
82
+
Teams should use [type annotations supported by TypeScript](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html).
83
+
84
+
Only if there is still evidence of insufficiency should [TypeScript](https://www.typescriptlang.org/) be considered.
85
+
86
+
### When to use JSDoc
87
+
- Function parameters or return values are non-trivial types
88
+
- There is repeated ambiguity
89
+
- Developers frequently struggle to understand how to use a function or class
90
+
- Refactoring often causes avoidable runtime errors
91
+
- IDE auto-completion is frequently unhelpful or misleading
92
+
93
+
JSDoc should be used selectively as overuse can lead to the opposite effect, making code harder to read and maintain.
94
+
95
+
### When to use TypeScript
96
+
- When the above JSDoc criteria have been met _and_ one or more of the following apply
97
+
- Complex, deeply nested domain models that change frequently
98
+
- Heavy use of generics or polymorphic behaviour that cannot be easily expressed in JSDoc
99
+
- Persistent runtime errors caused by type-related issues
100
+
- Significant refactoring risk
101
+
- Multiple teams working on the same codebase
102
+
- Shared libraries where consumers are in different codebases
103
+
104
+
TypeScript is a restricted technology as for the majority of digital services developed in Defra, any benefits don't outweigh the overhead.
105
+
106
+
Teams adopting TypeScript are accepting the cost of doing so such as:
107
+
108
+
- Increased build complexity and time
109
+
- Additional developer training and onboarding time
110
+
- Potentially reduced agility due to the static type system
111
+
- More configuration and dependency management
112
+
- Potentially avoidable risk to delivery timelines
113
+
114
+
Use of TypeScript must be approved at the appropriate governance level. Please speak to a Principal Developer for more information.
115
+
116
+
> TypeScript is a new addition to this standard and its usage has been long debated and there remain strong views for and against within the community. By allowing TypeScript in restricted scenarios we do not expect teams to start using it by default, nor do we support teams assessing existing JavaScript code as "technical debt", pushing the cost of unnecessary TypeScript migration to Defra.
79
117
80
118
## We use the Hapi framework to develop in Node.js
81
119
Hapi is already in use in Defra digital services and has provided a productive level of standardisation across
@@ -107,3 +145,7 @@ It is also the language that is best supported in open source .NET managed frame
107
145
## We use .NET Core wherever practical in preference to .NET Framework
108
146
.NET Core is Microsoft's strategic direction for .NET and gives all the benefits of being open source and cross platform,
0 commit comments