From c3ba8b58b86a55613f48d28c4fd6ce72eb0df29b Mon Sep 17 00:00:00 2001 From: Andrii Kirmas Date: Thu, 11 Mar 2021 10:00:09 +0300 Subject: [PATCH] #24 Recover el-mod shortcut in bem --- __recipes__/index.test.ts | 1 - src/bem.types.test.ts | 2 -- src/bem.types.ts | 13 +++++++------ src/ts-swiss.types.ts | 5 ++++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/__recipes__/index.test.ts b/__recipes__/index.test.ts index b753bb0..501790a 100644 --- a/__recipes__/index.test.ts +++ b/__recipes__/index.test.ts @@ -28,7 +28,6 @@ it("go", () => { const bem = classBeming & ClassNamed>() expect(bem(true, { "block": { - //@ts-expect-error //TODO Recover shortcut "&": "m", "el": {"m": "X"} } diff --git a/src/bem.types.test.ts b/src/bem.types.test.ts index 0b2bbaa..5c26baf 100644 --- a/src/bem.types.test.ts +++ b/src/bem.types.test.ts @@ -35,7 +35,6 @@ describe("BemQuery", () => { //@ts-expect-error "el=1": {block: {el: 1}}, "el": {block: {el: true}}, - //@ts-expect-error //TODO Recover shortcut "el: mod": {block: {el: "mod"}}, "el: -mod": {block: {el: {mod: false}}}, "el: +mod": {block: {el: {mod: true}}} @@ -73,7 +72,6 @@ describe("BemQuery", () => { //@ts-expect-error "el": {block: {el: true}}, "$": {block: {$: true}}, - //@ts-expect-error //TODO Recover shortcut "$: mod": {block: {$: "mod"}}, "$: +mod": {block: {$: {mod: true}}}, "$: -mod": {block: {$: {mod: false}}}, diff --git a/src/bem.types.ts b/src/bem.types.ts index a3c6402..8875d84 100644 --- a/src/bem.types.ts +++ b/src/bem.types.ts @@ -2,6 +2,7 @@ import type { CssModule } from "./definitions.types" import type { Subest, Strip, + PartDeep, // PartDeep } from "./ts-swiss.types" import type { ClassNamed } from "./main.types" @@ -29,14 +30,14 @@ export type BemQuery< bModKey extends string = "blockModKey" extends keyof ReactClassNaming.BemOptions ? ReactClassNaming.BemOptions["blockModKey"] : ReactClassNaming.BemOptions["$default"]["blockModKey"], -> = string extends classes ? BemAbsraction : { - [b in Strip, delE>]?: boolean | ( - // [classes extends `${b}${delE | delM}${string}` ? true : never] extends [never] ? never : +> = string extends classes ? BemAbsraction : PartDeep<{ + [b in Strip, delE>]: boolean | ( Extends]?: boolean + [e in Elements]: boolean + | (MVs extends `${string}${delM}${string}` ? never : MVs) | ( - {[m in Strip, delM>]?: + {[m in Strip, delM>]: classes extends `${b}${ e extends bModKey ? "" : `${delE}${e}` }${delM}${m}${delM}${infer V}` @@ -48,7 +49,7 @@ export type BemQuery< > // : never ) -} +}> type Extends = [T extends V ? true : never] extends [never] ? never : X diff --git a/src/ts-swiss.types.ts b/src/ts-swiss.types.ts index 0711297..4739854 100644 --- a/src/ts-swiss.types.ts +++ b/src/ts-swiss.types.ts @@ -27,4 +27,7 @@ export type Cut = Str extends `${s export type Subest = Base extends Extendent ? Extendent : Base // export type SubestDeep = Base extends Extendent ? Extendent : Base -export type PartDeep = Exclude | {[K in keyof Extract]?: Extract[K]} +export type PartDeep = Exclude | ( + // [Extract] extends [never] ? never : + T extends AnyObject ? {[K in keyof Extract]?: PartDeep[K]>} : never +)