exercism / exercism/typescript

Type errors in anagram tests when strict mode is enabled

Đang mở
#1,594 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
165
Fork
173
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

https://github.com/exercism/typescript/blob/4026d9e897e1a0c93e6b42f3bd0cb72fc0d1eeaf/exercises/practice/anagram/anagram.test.ts#L11

In the provided Jest tests for the anagram exercise, several expected arrays are declared empty without an explicit type annotation.
When the TypeScript compiler is run with "strict": true (as it is in the default Exercism TypeScript tsconfig), noImplicitAny is also enabled by default. This causes TypeScript compilation errors for these untyped empty arrays.

Steps to Reproduce
1. Download the anagram exercise for the TypeScript track.
2. Install dependencies:
```bash
yarn install
```
3. Run test:
```bash
yarn test`
```

Actual Behavior:
Typescript reports errors like
```bash
anagram.test.ts:66:11 - error TS7034: Variable 'expected' implicitly has type 'any[]' in some locations where its type cannot be determined.
```

Expected Behavior
The tests should compile successfully under the default configuration without requiring learners to change type annotations locally.

Proposed Fix
Add explicit type annotations for all empty expected arrays. For example:
```diff
- const expected = []
+ const expected: string[] = []
```

Why this helps
- Keeps the tests type-safe while still compiling with "strict": true.
- Prevents learners from hitting compiler errors unrelated to the exercise logic.
- Makes the learning experience smoother without weakening the strictness settings.
- I would be happy to open a pull request with the fix if that would be helpful.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.