Skip to content

Commit ce6ef16

Browse files
author
Johan Borestad
committed
Add GenericsExample1
1 parent a0076f1 commit ce6ef16

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,21 @@ test('GetterSetter()', t => {
2525
foo.bar = 'world'
2626
t.is(foo.bar, 'Hello world')
2727
})
28+
29+
test('GenericsExample1 - #1 - Using strings', t => {
30+
const gen1 = new x.GenericsExample1<string>()
31+
gen1.setValue('Hello World')
32+
t.is(
33+
gen1.getValue().toLowerCase(),
34+
'hello world'
35+
)
36+
})
37+
38+
test('GenericsExample1 - #2 - Using numbers', t => {
39+
const gen1 = new x.GenericsExample1<number>()
40+
gen1.setValue(2.00)
41+
t.is(
42+
gen1.getValue().valueOf(),
43+
2
44+
)
45+
})

src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ export class GetterSetter {
2727
this._val = val
2828
}
2929
}
30+
31+
export class GenericsExample1<T> {
32+
value: T
33+
setValue(value: T) {
34+
this.value = value
35+
}
36+
getValue(): T {
37+
return this.value
38+
}
39+
}

0 commit comments

Comments
 (0)