Remove @ts-ignore comments in 03-array by fixing root causes#255
Merged
Conversation
- 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes all spurious
@ts-ignorecomments fromsrc/03-array/by fixing the underlying type issues properly.Root causes & fixes
Duplicate identifiers across files (most of the
@ts-ignoreinstances)Multiple files all declared
const numbers,const friends,const namesat the top level. Because none hadimport/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.ts03-iterator-functions.ts04-searching-sorting.ts05-transforming-array.ts06-other-methods.ts09-arrays-typescript.tsDouble declaration in same file
05-transforming-array.tsdeclaredconst numberstwice. The second declaration (used forreduceexamples) was renamed toconst numbersForReduce.Untyped function parameters
compareNumbers(a, b)in04-searching-sorting.ts→ typed as(a: number, b: number): numbercompareFriends(friendA, friendB)→ typed using a localFriendinterfaceprintMultidimensionalArray(myArray)in07-multidimensional-arrays.ts→ typed asnumber[][]Also typed
friendsin09-arrays-typescript.ts→ typed asFriend[]What was intentionally kept
All
@ts-ignorecomments on theArray.prototypeextensions in02-adding-removing-elements.tsare retained — those are educational examples of prototype extension.