Skip to content

Commit

Permalink
Add TS trick to use result as string
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Feb 6, 2021
1 parent bb57f7d commit 3dd13a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ it("TypeScript manipulations", () => {

React_createElement(
{
//@ts-expect-error
"className": classNaming({"class1": undefined})
"className": classNaming<string>({"class1": undefined})
}
)

Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export {
classNaming
}

function classNaming(
function classNaming<O>(
/** Comment */
classNames: ClassNamesMap<string>
): ClassName;
function classNaming(
): O extends string ? string : ClassName;
function classNaming<O>(
className: undefined|string,
classNames: ClassNamesMap<string>
): ClassName;
): O extends string ? string : ClassName;
function classNaming(...args: any[]) {
return _classNaming(args.pop(), args.pop())
}
Expand Down

0 comments on commit 3dd13a8

Please sign in to comment.