Skip to content

Commit

Permalink
fix: make Tersible generic
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Nov 26, 2017
1 parent 7d3b85f commit 6293054
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/tersible.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('inject to class', t => {
return `a = ${this.a}`
})

let f = new Foo() as Foo & Tersible
let f = new Foo() as Tersible<Foo>
t.is(f.tersify(), 'a = 1')

f.a = 2
Expand Down
8 changes: 4 additions & 4 deletions src/tersible.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Tersible {
export type Tersible<T> = T & {
tersify(): string
}

Expand Down Expand Up @@ -29,7 +29,7 @@ export function Tersiblized<C extends new (...args: any[]) => {}>(Base: C, tersi
* but it cannot be done otherwise.
* How can I "clone" a function or class?
*/
export function tersible<T>(subject: T, tersify: (this: T) => string): T & Tersible {
export function tersible<T>(subject: T, tersify: (this: T) => string): Tersible<T> {
return Object.assign(
subject,
{
Expand All @@ -38,6 +38,6 @@ export function tersible<T>(subject: T, tersify: (this: T) => string): T & Tersi
)
}

export function isTersible(obj): obj is Tersible {
return typeof obj.tersify === 'function'
export function isTersible<T>(obj: T): obj is Tersible<T> {
return typeof obj['tersify'] === 'function'
}

0 comments on commit 6293054

Please sign in to comment.