Skip to content

Remove @ts-ignore comments in 03-array by fixing root causes#255

Merged
loiane merged 1 commit into
mainfrom
loiane/fix-ts-ignore
Jul 1, 2026
Merged

Remove @ts-ignore comments in 03-array by fixing root causes#255
loiane merged 1 commit into
mainfrom
loiane/fix-ts-ignore

Conversation

@loiane

@loiane loiane commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Removes all spurious @ts-ignore comments from src/03-array/ by fixing the underlying type issues properly.

Root causes & fixes

Duplicate identifiers across files (most of the @ts-ignore instances)

Multiple files all declared const numbers, const friends, const names at the top level. Because none had import/export, TypeScript treated them as scripts sharing global scope, causing identifier conflicts.

Fix: Added export {} to 6 files to make each a proper module with its own scope:

  • 02-adding-removing-elements.ts
  • 03-iterator-functions.ts
  • 04-searching-sorting.ts
  • 05-transforming-array.ts
  • 06-other-methods.ts
  • 09-arrays-typescript.ts

Double declaration in same file

05-transforming-array.ts declared const numbers twice. The second declaration (used for reduce examples) was renamed to const numbersForReduce.

Untyped function parameters

  • compareNumbers(a, b) in 04-searching-sorting.ts → typed as (a: number, b: number): number
  • compareFriends(friendA, friendB) → typed using a local Friend interface
  • printMultidimensionalArray(myArray) in 07-multidimensional-arrays.ts → typed as number[][]

Also typed

  • friends in 09-arrays-typescript.ts → typed as Friend[]

What was intentionally kept

All @ts-ignore comments on the Array.prototype extensions in 02-adding-removing-elements.ts are retained — those are educational examples of prototype extension.

- Add export {} to 02-adding-removing-elements.ts, 03-iterator-functions.ts,
  04-searching-sorting.ts, 05-transforming-array.ts, 06-other-methods.ts,
  09-arrays-typescript.ts to isolate each file as its own module, fixing
  duplicate identifier errors for numbers/friends/names across files
- Rename second const numbers to numbersForReduce in 05-transforming-array.ts
  (same file redeclaration)
- Add explicit types to compareNumbers(a,b) and compareFriends(a,b) in
  04-searching-sorting.ts
- Type printMultidimensionalArray parameter as number[][] in
  07-multidimensional-arrays.ts
- Type friends as Friend[] in 09-arrays-typescript.ts
- Retain @ts-ignore on Array.prototype extensions in
  02-adding-removing-elements.ts (intentional for educational purposes)
@loiane loiane merged commit d0c5229 into main Jul 1, 2026
1 check passed
@loiane loiane deleted the loiane/fix-ts-ignore branch July 1, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant