Skip to content

Commit 2c701a9

Browse files
committed
feat(tsconfig.json): improve type safety
1 parent cdb6b01 commit 2c701a9

File tree

7 files changed

+129
-157
lines changed

7 files changed

+129
-157
lines changed

__tests__/enumerable.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import test from 'ava'
22

3-
import Enumerable from '../src/enumerable'
3+
import Enumerable from '../src/enumerable.js'
44

55
test('Range', t => {
66
t.deepEqual(
77
Enumerable.Range(1, 10)
8-
.Select(x => x * x)
8+
.Select((x: number) => x * x)
99
.ToArray(),
1010
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
1111
)

__tests__/list.test.ts

Lines changed: 25 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
22

3-
import List from '../src/list'
3+
import List from '../src/list.js'
44

55
interface IPackage {
66
Company: string
@@ -561,13 +561,11 @@ test('LastOrDefault', t => {
561561
t.is(new List<string>().LastOrDefault('default'), 'default')
562562
})
563563

564-
565564
test('Max', t => {
566565
const people = new List<IPerson>([
567566
{ Age: 50, Name: 'Bob' },
568567
{ Age: 15, Name: 'Cathy' },
569568
{ Age: 25, Name: 'Alice' }
570-
571569
])
572570
t.is(
573571
people.Max(x => x.Age ?? 0),
@@ -587,8 +585,8 @@ test('Max_invalid_function_provided', t => {
587585
])
588586

589587
// Provide an invalid selector (wrong type) to trigger the error
590-
let invalidFn = () => 0;
591-
588+
let invalidFn = () => 0
589+
592590
t.throws(() => people.Max(invalidFn), {
593591
message: /InvalidOperationException: Invalid comparer or selector function provided./
594592
})
@@ -609,10 +607,7 @@ test('Max_undefinedComparer', t => {
609607
test('Max_emptyElements', t => {
610608
const people = new List<IPerson>([])
611609

612-
t.is(
613-
people.Max(),
614-
undefined
615-
)
610+
t.is(people.Max(), undefined)
616611
})
617612

618613
test('Max_comparer', t => {
@@ -622,58 +617,31 @@ test('Max_comparer', t => {
622617
{ Age: 50, Name: 'Bob' }
623618
])
624619

625-
let comparer = ((a: IPerson, b: IPerson) => (a.Age ?? 0) - (b.Age ?? 0));
626-
627-
t.is(
628-
people.Max(comparer),
629-
people.Last()
630-
);
620+
let comparer = (a: IPerson, b: IPerson) => (a.Age ?? 0) - (b.Age ?? 0)
621+
622+
t.is(people.Max(comparer), people.Last())
631623
})
632624

633625
test('Max_number', t => {
634-
const nums = new List<number>([
635-
5,
636-
10,
637-
-5
638-
])
639-
t.is(
640-
nums.Max(),
641-
10
642-
)
626+
const nums = new List<number>([5, 10, -5])
627+
t.is(nums.Max(), 10)
643628
})
644629

645630
test('Max_string', t => {
646-
const people = new List<string>([
647-
'Cathy',
648-
'Alice',
649-
'Bob'
650-
])
651-
t.is(
652-
people.Max(),
653-
'Cathy'
654-
)
631+
const people = new List<string>(['Cathy', 'Alice', 'Bob'])
632+
t.is(people.Max(), 'Cathy')
655633
})
656634

657635
test('Max_boolean', t => {
658-
const bools = new List<boolean>([
659-
true,
660-
false,
661-
true,
662-
false
663-
])
664-
t.is(
665-
bools.Max(),
666-
true
667-
)
636+
const bools = new List<boolean>([true, false, true, false])
637+
t.is(bools.Max(), true)
668638
})
669639

670-
671640
test('Min', t => {
672641
const people = new List<IPerson>([
673642
{ Age: 50, Name: 'Bob' },
674643
{ Age: 15, Name: 'Cathy' },
675644
{ Age: 25, Name: 'Alice' }
676-
677645
])
678646
t.is(
679647
people.Min(x => x.Age ?? 0),
@@ -693,8 +661,8 @@ test('Min_invalid_function_provided', t => {
693661
])
694662

695663
// Provide an invalid selector (wrong type) to trigger the error
696-
let invalidFn = () => 0;
697-
664+
let invalidFn = () => 0
665+
698666
t.throws(() => people.Min(invalidFn), {
699667
message: /InvalidOperationException: Invalid comparer or selector function provided./
700668
})
@@ -719,58 +687,30 @@ test('Min_comparer', t => {
719687
{ Age: 50, Name: 'Bob' }
720688
])
721689

722-
let comparer = ((a: IPerson, b: IPerson) => (a.Age ?? 0) - (b.Age ?? 0));
723-
724-
t.is(
725-
people.Min(comparer),
726-
people.First()
727-
);
690+
let comparer = (a: IPerson, b: IPerson) => (a.Age ?? 0) - (b.Age ?? 0)
691+
692+
t.is(people.Min(comparer), people.First())
728693
})
729694

730695
test('Min_emptyElements', t => {
731696
const people = new List<IPerson>([])
732697

733-
t.is(
734-
people.Min(),
735-
undefined
736-
)
698+
t.is(people.Min(), undefined)
737699
})
738700

739701
test('Min_number', t => {
740-
const nums = new List<number>([
741-
10,
742-
5,
743-
-5
744-
])
745-
t.is(
746-
nums.Min(),
747-
-5
748-
)
702+
const nums = new List<number>([10, 5, -5])
703+
t.is(nums.Min(), -5)
749704
})
750705

751706
test('Min_string', t => {
752-
const people = new List<string>([
753-
'Cathy',
754-
'Alice',
755-
'Bob'
756-
])
757-
t.is(
758-
people.Min(),
759-
'Alice'
760-
)
707+
const people = new List<string>(['Cathy', 'Alice', 'Bob'])
708+
t.is(people.Min(), 'Alice')
761709
})
762710

763711
test('Min_boolean', t => {
764-
const bools = new List<boolean>([
765-
true,
766-
false,
767-
true,
768-
false
769-
])
770-
t.is(
771-
bools.Min(),
772-
false
773-
)
712+
const bools = new List<boolean>([true, false, true, false])
713+
t.is(bools.Min(), false)
774714
})
775715

776716
test('OfType', t => {

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "LinQ + TypeScript",
55
"es2015": "index.ts",
66
"source": "index.ts",
7+
"type": "module",
78
"main": "dist/src/index.js",
89
"types": "dist/src/index.d.ts",
910
"scripts": {
@@ -69,14 +70,14 @@
6970
}
7071
},
7172
"ava": {
73+
"files": [
74+
"dist/__tests__/**/*.js"
75+
],
7276
"typescript": {
7377
"rewritePaths": {
74-
"src/": "build/"
78+
"src/": "dist/src/"
7579
},
7680
"compile": "tsc"
77-
},
78-
"require": [
79-
"ts-node/register"
80-
]
81+
}
8182
}
8283
}

src/enumerable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import List from './list'
1+
import List from './list.js'
22

33
export default class Enumerable {
44
/**

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* Copyright © 2016 Flavio Corpa. All rights reserved.
88
*
99
*/
10-
export { default as List } from './list'
11-
export { default as Enumerable } from './enumerable'
10+
export { default as List } from './list.js'
11+
export { default as Enumerable } from './enumerable.js'

0 commit comments

Comments
 (0)