Skip to content

Commit 8f26fc4

Browse files
authored
Merge pull request #4 from danadajian/patch-1
turn on noUncheckedIndexedAccess TS rule
2 parents 5b70f3c + 299532d commit 8f26fc4

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,20 @@ export const cors =
208208
if (origins.length) {
209209
const from = request.headers.get('Origin') ?? ''
210210
for (let i = 0; i < origins.length; i++) {
211-
const value = processOrigin(origins[i], request, from)
212-
if (value === true) {
213-
set.headers['Vary'] = origin ? 'Origin' : '*'
214-
set.headers['Access-Control-Allow-Origin'] =
215-
request.headers.get('Origin') ?? '*'
216-
217-
return
211+
const currentOrigin = origins[i];
212+
if (currentOrigin) {
213+
const value = processOrigin(currentOrigin, request, from)
214+
if (value === true) {
215+
set.headers['Vary'] = origin ? 'Origin' : '*'
216+
set.headers['Access-Control-Allow-Origin'] =
217+
request.headers.get('Origin') ?? '*'
218+
219+
return
220+
}
221+
222+
// value can be string (truthy value) but not `true`
223+
if (value) headers.push(value)
218224
}
219-
220-
// value can be string (truthy value) but not `true`
221-
if (value) headers.push(value)
222225
}
223226
}
224227

tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
9191
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
9292
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
93+
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
9494
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
9595
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
9696
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */

tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
9191
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
9292
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
93+
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
9494
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
9595
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
9696
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
9191
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
9292
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
93+
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
9494
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
9595
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
9696
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */

0 commit comments

Comments
 (0)