Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent widening of type if >1 union-type is string with ElementAttributes #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LumeElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {render} from 'solid-js/web'
// element preupgrade value.
import {Effectful, __isPropSetAtLeastOnce} from 'classy-solid'

import type {DashCasedProps, IsString} from './_utils'
import type {AttributeHandler} from './attribute'
import type {DashCasedProps} from './_utils'

// TODO `templateMode: 'append' | 'replace'`, which allows a subclass to specify
// if template content replaces the content of `root`, or is appended to `root`.
Expand Down Expand Up @@ -459,5 +459,5 @@ export type ElementAttributes<
Omit<JSX.HTMLAttributes<ElementType>, SelectedProperties | keyof AdditionalProperties>

type WithStringValues<Type extends object> = {
[Property in keyof Type]: NonNullable<Type[Property]> extends string ? Type[Property] : Type[Property] | string
[Property in keyof Type]: IsString<Type[Property]> extends false ? Type[Property] | string : Type[Property]
}
8 changes: 8 additions & 0 deletions src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,11 @@ export type DashCasedProps<T> = {
// fooBar: string;
// foo: number;
// }

/**
* Returns
* - `true` if all of union-types are `string`
* - `false` if none of union-types are `string`
* - `boolean` if >1 of union-types are `string`
*/
export type IsString<U> = U extends string ? true : false