Skip to content

Commit 4711d73

Browse files
committed
Attempt to improve types.
1 parent 9429dec commit 4711d73

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

classcat.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
export as namespace Classcat
22

3-
export interface ClassSet {
4-
[key: string]: boolean | any | ClassSet
3+
export interface ClassObject {
4+
[key: string]: boolean | any
55
}
66

7-
export type Class = string | number | ClassSet
7+
export interface ClassArray extends Array<Class> {}
8+
9+
export type Class = string | number | ClassObject | ClassArray
810

911
/**
1012
* Classcat is a unary function (accepts a single argument) expecting an array of elements or an object of keys and returns a string that is the result of joining all elements of the array or object keys.
1113
*
1214
* If the value associated with a given key is falsey, the key will be ignored.
1315
*
1416
* @param classes
15-
*/
16-
export default function(classes: Class | Class[]): string
17+
*/
18+
export default function(classes: Class): string

tests/ts/index.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import cc from "classcat"
22

33
let className: string
44

5+
className = cc(0)
6+
57
className = cc("btn")
68

7-
className = cc(12)
9+
className = cc(["btn", "btn-active"])
10+
11+
className = cc([["btn", "btn-active"]])
812

913
className = cc({
1014
btn: true
1115
})
1216

13-
className = cc(["btn", "btn-active"])
14-
1517
className = cc([
16-
"btn",
1718
{
18-
btn: {
19-
"--success": true
20-
}
19+
btn: true
2120
}
2221
])

0 commit comments

Comments
 (0)