Skip to content

Commit 933a1ae

Browse files
author
Andrii Kirmas
committed
Move chainable notation to type alias
1 parent 5c568c5 commit 933a1ae

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/direct.test.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,40 @@ describe(direct.name, () => {
1616
).toBe(
1717
className
1818
))
19-
it("called", () => expect({
20-
...output({
19+
20+
describe("chained", () => {
21+
const chained = output({
2122
class3: undefined, class4: "hash4"
2223
})
23-
}).toStrictEqual({
24-
"className": `${className} class3 hash4`
25-
}))
26-
it("called is strigable", () => expect(
27-
`${output({
28-
class3: undefined, class4: "hash4"
29-
})}`
30-
).toBe(
31-
`${className} class3 hash4`
32-
))
24+
, nextClassName = `${className} class3 hash4`
25+
26+
it("called", () => expect({
27+
...chained
28+
}).toStrictEqual({
29+
className: nextClassName
30+
}))
31+
it("called is strigable", () => expect(
32+
`${chained}`
33+
).toBe(
34+
nextClassName
35+
))
36+
it("TBD call is not allow by TS on key duplication", () => expect(
37+
//TODO //@ts-expect-error`
38+
`${chained({class1: undefined})}`
39+
).toBe(
40+
`${nextClassName} class1`
41+
))
42+
})
3343
})
3444

45+
type ClassNamingChain = {
46+
className: string
47+
(classes: Record<string, ClassValue>): ClassNamingChain
48+
}
49+
3550
function direct<T extends Record<string, ClassValue>>(classes: T, propagate?: string) {
3651
const className = joinWithLead(propagate, dehash(classes))
37-
, host = (classes: Record<string, ClassValue>) => direct(classes, className)
52+
, host: ClassNamingChain = classes => direct(classes, className)
3853

3954
host["className"] = className
4055
stringifyClassNamed(host)

0 commit comments

Comments
 (0)