Skip to content

Commit 10563ae

Browse files
author
Andrii Kirmas
committed
Delete redundant helper
1 parent ee8b752 commit 10563ae

File tree

3 files changed

+16
-100
lines changed

3 files changed

+16
-100
lines changed

src/defs.spec.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import { Component } from "react";
1+
import { Component, PureComponent } from "react";
22
import type { ClassNames } from "./defs";
33

4-
type ClassNamesSingleton<C extends string> = {classNames: Record<C, string|undefined>}
5-
6-
class ClassComponent extends Component<ClassNamesSingleton<"component">> {}
7-
class ClassPureComponent extends Component<ClassNamesSingleton<"pureComponent">> {}
8-
function Functional(_: ClassNamesSingleton<"functional">) {
9-
return null
10-
}
11-
type ComponentProps= ClassNamesSingleton<"props">
12-
4+
type Props = ClassNames<true, "props">
5+
function Functional(_: ClassNames<"functional">) { return null }
6+
class ClassComponent extends Component<ClassNames<"component"|"comp0">> {}
7+
class ClassPureComponent extends PureComponent<ClassNames<"pureComponent">> {}
138

149
describe("ClassNames", () => {
1510
it("<true>", () => {
@@ -76,7 +71,7 @@ describe("ClassNames", () => {
7671
expect(suites).toBeInstanceOf(Object)
7772
})
7873
})
79-
describe("", () => {
74+
describe("Miss-use", () => {
8075
it("<'class1', true>", () => {
8176
const suite1
8277
//@ts-expect-error Type 'boolean' does not satisfy the constraint 'never'
@@ -114,17 +109,18 @@ describe("ClassNamesFrom", () => {
114109

115110
it("manually merge", () => {
116111
type AppClassNames = (
117-
ClassNamesSingleton<"App">
112+
ClassNames<"App">
118113
& ClassNames<typeof ClassComponent>
119114
& ClassNames<typeof ClassPureComponent>
120115
& ClassNames<typeof Functional>
121-
& ClassNames<ComponentProps>
116+
& ClassNames<Props>
122117
)["classNames"];
123118

124119
const suites: Record<string, AppClassNames> = {
125120
"exact": {
126121
App: undefined,
127122
component: undefined,
123+
comp0: undefined,
128124
functional: undefined,
129125
props: undefined,
130126
pureComponent: undefined
@@ -179,18 +175,20 @@ describe("ClassNamesFrom", () => {
179175
})
180176

181177
it("multiple apply", () => {
182-
type AppClassnames = ClassNames<
178+
type AppClassNames = ClassNames<
179+
true,
183180
"App",
184181
typeof ClassComponent,
185182
typeof ClassPureComponent,
186183
typeof Functional,
187-
ComponentProps
184+
Props
188185
>["classNames"];
189186

190-
const suites: Record<string, AppClassnames> = {
187+
const suites: Record<string, AppClassNames> = {
191188
"exact": {
192189
App: undefined,
193190
component: undefined,
191+
comp0: undefined,
194192
functional: undefined,
195193
props: undefined,
196194
pureComponent: undefined

src/defs.test.ts

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
1-
import type { JSXElementConstructor } from "react";
21
import { Component } from "react";
3-
import type { ClassNamesProp, ClassNamesStrict, GetClassKeys } from "./defs";
2+
import type { ClassNamesProp, GetClassKeys } from "./defs";
43

5-
class ClassComponent0 extends Component<ClassNamesStrict<never, "comp1"|"comp2">> {}
6-
class ClassComponent1 extends Component<ClassNamesStrict<true, never>> {}
7-
class ClassComponent2 extends Component<ClassNamesStrict<true, "comp1"|"comp2">> {}
8-
9-
describe("ClassNamesStrict", () => {
10-
it("<never, 'class1'|'class2'>", () => {
11-
const suites: Record<string, ClassNamesStrict<never, 'class1'|'class2'>> = {
12-
"good": {
13-
classNames: {
14-
class1: undefined,
15-
class2: undefined
16-
}
17-
}
18-
}
19-
expect(suites).toBeInstanceOf(Object)
20-
})
21-
it("ClassComponent0", () => {
22-
const suites: Record<string, ClassNamesStrict<never, never, typeof ClassComponent0>> = {
23-
"good": {
24-
classNames: {
25-
comp1: undefined,
26-
comp2: undefined,
27-
//@ts-expect-error Object literal may only specify known properties, and 'redundant' does not exist
28-
redundant: undefined
29-
}
30-
},
31-
"omitted": {
32-
//@ts-expect-error Property 'comp2' is missing in type
33-
classNames: {
34-
comp1: undefined,
35-
}
36-
}
37-
}
38-
expect(suites).toBeInstanceOf(Object)
39-
})
40-
})
4+
class ClassComponent0 extends Component<ClassNamesProp<"comp1"|"comp2">> {}
415

426
describe("GetClassKeys", () => {
437
it("ClassComponent", () => {
@@ -50,20 +14,3 @@ describe("GetClassKeys", () => {
5014
expect(suites).toBeInstanceOf(Object)
5115
})
5216
})
53-
54-
it("WithClassNames", () => {
55-
type WithClassNames = ClassNamesProp | JSXElementConstructor<ClassNamesProp>
56-
// | Component<ClassNamesProp> | (props: ClassNamesProp) => any
57-
58-
const suites: Record<string, WithClassNames> = {
59-
ClassComponent0,
60-
//TODO
61-
//@ts-expect-error Property 'className' is missing
62-
ClassComponent1,
63-
//TODO
64-
//@ts-expect-error Property 'className' is missing
65-
ClassComponent2,
66-
}
67-
68-
expect(suites).toBeInstanceOf(Object)
69-
})

src/defs.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,6 @@ export type ClassNames<
3434
| GetClassKeys<C10>
3535
>
3636

37-
38-
export type ClassNamesStrict<
39-
C0 extends true | never,
40-
C1 extends string | never = never,
41-
C2 extends ReactRelated = never,
42-
C3 extends ReactRelated = never,
43-
C4 extends ReactRelated = never,
44-
C5 extends ReactRelated = never,
45-
C6 extends ReactRelated = never,
46-
C7 extends ReactRelated = never,
47-
C8 extends ReactRelated = never,
48-
C9 extends ReactRelated = never,
49-
C10 extends ReactRelated = never,
50-
C11 extends ReactRelated = never
51-
>
52-
= Ever<C0, {className: string}> & ClassNamesProp<C1
53-
> & ClassNamesProp<C1
54-
| GetClassKeys<C2>
55-
| GetClassKeys<C3>
56-
| GetClassKeys<C4>
57-
| GetClassKeys<C5>
58-
| GetClassKeys<C6>
59-
| GetClassKeys<C7>
60-
| GetClassKeys<C8>
61-
| GetClassKeys<C9>
62-
| GetClassKeys<C10>
63-
| GetClassKeys<C11>
64-
>
65-
6637
export type ReactRelated = Record<string, any> | JSXElementConstructor<any>
6738

6839
export type ClassNamesProp<C extends string = string> = Ever<C, {classNames: ClassNamesMap<C>}>

0 commit comments

Comments
 (0)