Skip to content

Commit 9b8b0be

Browse files
Update TypeScript context in Node.js standards (#114)
1 parent ba1dfca commit 9b8b0be

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

docs/standards/development_language_standards.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,49 @@ application performance in most Web-facing scenarios.
7171
This can be seen across government as well, in particular the GDS front end community tend to publish their products
7272
so that they can be easily used in Ruby and Node.js, in particular.
7373

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.
7676

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.
79117
80118
## We use the Hapi framework to develop in Node.js
81119
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
107145
## We use .NET Core wherever practical in preference to .NET Framework
108146
.NET Core is Microsoft's strategic direction for .NET and gives all the benefits of being open source and cross platform,
109147
including growing community support.
148+
149+
## Significant changes
150+
151+
- TypeScript usage guidance added December 2025

docs/standards/javascript_standards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## JavaScript standards
22

3-
Use vanilla JavaScript, don't use extensions to the language such as TypeScript
3+
Use vanilla JavaScript in the first instance, don't use extensions to the language such as TypeScript without an approved exception.
44

55
### Use [neostandard](https://github.com/neostandard/neostandard) to lint your code
66

0 commit comments

Comments
 (0)