diff --git a/projects/cdk/types/index.ts b/projects/cdk/types/index.ts index 691b4f57d788f..ec6a121414f3e 100644 --- a/projects/cdk/types/index.ts +++ b/projects/cdk/types/index.ts @@ -4,4 +4,5 @@ export * from './mapper'; export * from './matcher'; export * from './rounding'; export * from './safe-html'; +export * from './suggestive-string'; export * from './values-of'; diff --git a/projects/cdk/types/suggestive-string.ts b/projects/cdk/types/suggestive-string.ts new file mode 100644 index 0000000000000..9d9b407569882 --- /dev/null +++ b/projects/cdk/types/suggestive-string.ts @@ -0,0 +1,11 @@ +export type TuiLooseUnion = + | U + | (U extends string + ? Record & string + : U extends number + ? Record & number + : U extends symbol + ? Record & symbol + : U extends bigint + ? Record & bigint + : never); diff --git a/projects/core/directives/appearance/appearance.options.ts b/projects/core/directives/appearance/appearance.options.ts index 23170b25c27f0..5705cf03b17dc 100644 --- a/projects/core/directives/appearance/appearance.options.ts +++ b/projects/core/directives/appearance/appearance.options.ts @@ -1,10 +1,11 @@ import type {ExistingProvider, ProviderToken} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; import {tuiCreateToken, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; /** * Bundled appearances for autocomplete purposes, not exported on purpose */ -type Appearance = +type Appearance = TuiLooseUnion< | 'accent' | 'destructive' | 'error' @@ -22,7 +23,7 @@ type Appearance = | 'textfield' | 'warning' | 'whiteblock' - | (Record & string); +>; export interface TuiAppearanceOptions { readonly appearance: Appearance; diff --git a/projects/core/pipes/flag/flag.pipe.ts b/projects/core/pipes/flag/flag.pipe.ts index 57dd8d0524b3a..f1ab82738279a 100644 --- a/projects/core/pipes/flag/flag.pipe.ts +++ b/projects/core/pipes/flag/flag.pipe.ts @@ -1,8 +1,11 @@ import type {PipeTransform} from '@angular/core'; import {inject, Pipe} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; import {TUI_ASSETS_PATH} from '@taiga-ui/core/tokens'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n/types'; +type IsoCode = TuiLooseUnion; + @Pipe({ standalone: true, name: 'tuiFlag', @@ -10,18 +13,10 @@ import type {TuiCountryIsoCode} from '@taiga-ui/i18n/types'; export class TuiFlagPipe implements PipeTransform { private readonly staticPath = inject(TUI_ASSETS_PATH); - public transform( - countryIsoCode: TuiCountryIsoCode | (Record & string), - ): string; - public transform( - countryIsoCode: TuiCountryIsoCode | (Record & string) | undefined, - ): string | null; - public transform( - countryIsoCode?: TuiCountryIsoCode | (Record & string) | null, - ): string | null; - public transform( - countryIsoCode?: TuiCountryIsoCode | (Record & string) | null, - ): string | null { + public transform(countryIsoCode: IsoCode): string; + public transform(countryIsoCode: IsoCode | undefined): string | null; + public transform(countryIsoCode?: IsoCode | null): string | null; + public transform(countryIsoCode?: IsoCode | null): string | null { if (!countryIsoCode) { return null; } diff --git a/projects/i18n/types/language-names.ts b/projects/i18n/types/language-names.ts index 9f935733fb1fd..de81ac6ca69c1 100644 --- a/projects/i18n/types/language-names.ts +++ b/projects/i18n/types/language-names.ts @@ -1,4 +1,6 @@ -export type TuiLanguageName = +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; + +export type TuiLanguageName = TuiLooseUnion< | 'belarusian' | 'chinese' | 'dutch' @@ -18,4 +20,4 @@ export type TuiLanguageName = | 'turkish' | 'ukrainian' | 'vietnamese' - | (Record & string); +>; diff --git a/projects/kit/components/badged-content/badged-content.directive.ts b/projects/kit/components/badged-content/badged-content.directive.ts index 76343c37a799e..ba6b002bc32c4 100644 --- a/projects/kit/components/badged-content/badged-content.directive.ts +++ b/projects/kit/components/badged-content/badged-content.directive.ts @@ -1,4 +1,5 @@ import {Directive, Input} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; @Directive({ standalone: true, @@ -6,5 +7,5 @@ import {Directive, Input} from '@angular/core'; }) export class TuiBadgedContentDirective { @Input() - public tuiSlot: 'bottom' | 'top' | (Record & string) = 'top'; + public tuiSlot: TuiLooseUnion<'bottom' | 'top'> = 'top'; } diff --git a/projects/layout/components/app-bar/app-bar.directive.ts b/projects/layout/components/app-bar/app-bar.directive.ts index eb9e7059994b5..391bb75b77b48 100644 --- a/projects/layout/components/app-bar/app-bar.directive.ts +++ b/projects/layout/components/app-bar/app-bar.directive.ts @@ -1,4 +1,5 @@ import {Directive, Input} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; @Directive({ standalone: true, @@ -6,5 +7,5 @@ import {Directive, Input} from '@angular/core'; }) export class TuiAppBarDirective { @Input() - public tuiSlot: 'left' | 'right' | (Record & string) = 'left'; + public tuiSlot: TuiLooseUnion<'left' | 'right'> = 'left'; } diff --git a/projects/layout/components/block-status/block-status.directive.ts b/projects/layout/components/block-status/block-status.directive.ts index 4c1cf63a59be7..5614e5dc86e5f 100644 --- a/projects/layout/components/block-status/block-status.directive.ts +++ b/projects/layout/components/block-status/block-status.directive.ts @@ -1,4 +1,5 @@ import {Directive, Input} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; @Directive({ standalone: true, @@ -6,5 +7,5 @@ import {Directive, Input} from '@angular/core'; }) export class TuiBlockStatusDirective { @Input() - public tuiSlot: 'action' | 'top' | (Record & string) = 'top'; + public tuiSlot: TuiLooseUnion<'action' | 'top'> = 'top'; } diff --git a/projects/legacy/directives/wrapper/wrapper.directive.ts b/projects/legacy/directives/wrapper/wrapper.directive.ts index 7ac1026492225..af1cb7e8334a8 100644 --- a/projects/legacy/directives/wrapper/wrapper.directive.ts +++ b/projects/legacy/directives/wrapper/wrapper.directive.ts @@ -1,4 +1,5 @@ import {Directive, Input} from '@angular/core'; +import type {TuiLooseUnion} from '@taiga-ui/cdk/types'; import type {TuiInteractiveState} from '@taiga-ui/core/types'; /** @@ -46,10 +47,7 @@ export class TuiWrapperDirective { return this.focus && !this.disabled; } - protected get interactiveState(): - | TuiInteractiveState - | (Record & string) - | null { + protected get interactiveState(): TuiLooseUnion | null { if (this.disabled) { return 'disabled'; }