Skip to content

Commit

Permalink
Merge pull request #7115 from TerriaJS/simplify-text-type
Browse files Browse the repository at this point in the history
Remove `OneKeyFrom` type check to reduce compile time.
  • Loading branch information
na9da committed Apr 29, 2024
2 parents 92c0afe + 94f5c66 commit f073bd1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/Styled/Box.tsx
@@ -1,6 +1,6 @@
import { Ref } from "react";
import styled from "styled-components";
import { OneKeyFrom, Overflow, WhiteSpace, WordBreak } from "./Styled.types";
import { Overflow, WhiteSpace, WordBreak } from "./Styled.types";

interface Column {
col1?: boolean;
Expand Down Expand Up @@ -68,7 +68,7 @@ export interface IBoxPropsBase {
as?: React.ElementType | keyof JSX.IntrinsicElements;
}

export type IBoxProps = IBoxPropsBase & OneKeyFrom<Column>;
export type IBoxProps = IBoxPropsBase & Column;

export const Box = styled.div<IBoxProps>`
display: flex;
Expand Down
6 changes: 0 additions & 6 deletions lib/Styled/Styled.types.ts
Expand Up @@ -23,12 +23,6 @@ export type WhiteSpace =
| "initial"
| "inherit";

export type OneKeyFrom<T, K extends keyof T = keyof T> = K extends any
? Pick<T, K> & Partial<Record<Exclude<keyof T, K>, never>> extends infer O
? { [P in keyof O]: O[P] }
: never
: never;

/**
* Types that can be used after upgrade to ts4.
*/
Expand Down
7 changes: 3 additions & 4 deletions lib/Styled/Text.tsx
@@ -1,6 +1,5 @@
import { ComponentProps } from "react";
import styled from "styled-components";
import { OneKeyFrom } from "./Styled.types";

interface ITextSize {
noFontSize?: boolean;
Expand Down Expand Up @@ -52,9 +51,9 @@ export interface ITextPropsBase {
}

export type ITextProps = ITextPropsBase &
OneKeyFrom<ITextSize> &
OneKeyFrom<ITextColor> &
OneKeyFrom<ITextWeight> &
ITextSize &
ITextColor &
ITextWeight &
ComponentProps<"div">;

// should it be a span or inline-block-div? - leaning to div
Expand Down

0 comments on commit f073bd1

Please sign in to comment.