Repository: express-rate-limit/express-rate-limit

Issue:
Incorrect type for DraftHeadersVersion
### Description

The type for `DraftHeadersVersion` is `string` rather than `"draft-6" | "draft-7" | "draft-8"`, this is because `SUPPORTED_DRAFT_VERSIONS` is defined as a string array rather than a const array

### Library version

7.5.0

### Node version

v22.14.0

### Typescript version (if you are using it)

5.2.2

### Module system

ESM

Discussion:

Solution patch:
diff --git a/source/headers.ts b/source/headers.ts
index 1709cbc..ef43d97 100644
--- a/source/headers.ts
+++ b/source/headers.ts
@@ -7,7 +7,11 @@ import type { Response } from 'express'
 import type { RateLimitInfo } from './types.js'
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
-export const SUPPORTED_DRAFT_VERSIONS = ['draft-6', 'draft-7', 'draft-8']
+export const SUPPORTED_DRAFT_VERSIONS = [
+	'draft-6',
+	'draft-7',
+	'draft-8',
+] as const
 
 /**
  * Returns the number of seconds left for the window to reset. Uses `windowMs`
diff --git a/source/validations.ts b/source/validations.ts
index dc4c91f..0c71774 100644
--- a/source/validations.ts
+++ b/source/validations.ts
@@ -261,6 +261,7 @@ const validations = {
 	headersDraftVersion(version?: any) {
 		if (
 			typeof version !== 'string' ||
+			// @ts-expect-error This is fine. If version is not in the array, it will just return false.
 			!SUPPORTED_DRAFT_VERSIONS.includes(version)
 		) {
 			const versionString = SUPPORTED_DRAFT_VERSIONS.join(', ')



Test patch:
diff --git a/test/library/options-test.ts b/test/library/options-test.ts
index 5c6ed5a..7f30a0d 100644
--- a/test/library/options-test.ts
+++ b/test/library/options-test.ts
@@ -95,4 +95,11 @@ describe('options test', () => {
 			})
 		}).toThrowError(/store/)
 	})
+
+	it('should not allow an invalid standardHeaders option', async () => {
+		rateLimit({
+			// @ts-expect-error Check correct typing of standardHeaders
+			standardHeaders: 'not-a-valid-draft',
+		})
+	})
 })