Skip to content

Commit

Permalink
Migrate to @import statements
Browse files Browse the repository at this point in the history
These are available in later versions of TypeScript and they're a lot
neater/easier to understand. Let's use them.
  • Loading branch information
rowanmanning committed Oct 17, 2024
1 parent ff4cf34 commit a56600c
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 21 deletions.
6 changes: 2 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* @typedef {import("express").Application} Application
* @typedef {import("./typings/n-express").Callback} Callback
* @typedef {import("./typings/n-express").AppOptions} AppOptions
* @typedef {import("./typings/n-express").AppContainer} AppContainer
* @import {Application} from 'express'
* @import {AppContainer, AppOptions, Callback} from './typings/n-express'
*/

require('isomorphic-fetch');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/guess-app-details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").AppMeta} AppMeta
* @import {AppMeta} from '../../typings/n-express'
*/

const normalizeName = require('./normalize-name');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/health-checks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import("express").Application} ExpressApp
* @typedef {import("../../typings/n-express").AppOptions} AppOptions
* @import {Application as ExpressApp} from 'express'
* @import {AppOptions} from '../../typings/n-express'
*/

const logger = require('@dotcom-reliability-kit/logger');
Expand Down
4 changes: 1 addition & 3 deletions src/middleware/anon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @typedef {import("../../typings/n-express").Request} Request
* @typedef {import("../../typings/n-express").Response} Response
* @import {Callback, Request, Response} from '../../typings/n-express'
*/

/**
Expand Down
5 changes: 2 additions & 3 deletions src/middleware/backend-authentication.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @typedef {import("express")} Express
* @typedef {import("../../typings/n-express").Callback} Callback
* @import Express from 'express'
*/

const logger = require('@dotcom-reliability-kit/logger');
Expand Down Expand Up @@ -39,7 +38,7 @@ module.exports = (app) => {

// @ts-ignore
app.use(
/** @type {Callback} */ (req, res, next) => {
/** @type {Express.Handler} */ (req, res, next) => {
// allow static assets, healthchecks, etc., through
if (req.path.indexOf('/__') === 0) {
next();
Expand Down
7 changes: 5 additions & 2 deletions src/middleware/cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @typedef {[key: keyof import("../../typings/n-express").CacheHeaders, val: string]} CacheHeader
* @import {Callback, CacheHeaders} from '../../typings/n-express'
*/

/**
* @typedef {[key: keyof CacheHeaders, val: string]} CacheHeader
*/

const cacheHeaders = {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/consent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/log-vary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

const logger = require('@dotcom-reliability-kit/logger');
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/robots.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

const fs = require('fs');
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/security.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/vary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/via.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("../../typings/n-express").Callback} Callback
* @import {Callback} from '../../typings/n-express'
*/

/**
Expand Down

0 comments on commit a56600c

Please sign in to comment.