}>
@@ -303,6 +389,18 @@ const uisHeaderMenuCompRenderNotMatchingOptionalProps = (
);
+//
+// HeaderMenuItem
+//
+
+const uisHeaderMenuItemRequiredChild = (
+ Required Child
+);
+
+//
+// UIShell Link
+//
+
interface TestCompPropsOverwrite {
element?: 'overwriteTest'; // making this required will produce an error. The underlying component will never receive prop element so it's not allowed to be required.
someProp: string;
diff --git a/types/carbon-components-react/lib/components/Button/Button.d.ts b/types/carbon-components-react/lib/components/Button/Button.d.ts
index 282b478a2f..009f29a486 100644
--- a/types/carbon-components-react/lib/components/Button/Button.d.ts
+++ b/types/carbon-components-react/lib/components/Button/Button.d.ts
@@ -1,30 +1,86 @@
import * as React from "react";
-import { EmbeddedIconProps, EmbeddedTooltipProps, ReactAnchorAttr, ReactButtonAttr, ReactCreateElementParam, RenderIconProps, SizingProps, } from "../../../typings/shared";
+import {
+ EmbeddedIconProps,
+ EmbeddedTooltipProps,
+ ReactButtonAttr,
+ FCReturn, JSXIntrinsicElementProps, ReactAnchorAttr, ForwardRefProps,
+} from '../../../typings/shared';
export type ButtonKind = "danger" | "danger--primary" | "ghost" | "primary" | "secondary" | "tertiary";
export type ButtonSize = "default" | "field" | "small";
-interface InheritedButtonProps extends ReactButtonAttr { }
-
-interface InheritedAnchorProps extends ReactAnchorAttr { }
-
-interface SharedProps extends
- EmbeddedIconProps,
- EmbeddedTooltipProps,
- RenderIconProps,
- SizingProps
-{
- as?: ReactCreateElementParam,
- hasIconOnly?: boolean,
- kind?: ButtonKind, // required but has default value
- size?: ButtonSize,
+export interface ButtonRenderIconRenderProps {
+ "aria-hidden"?: boolean;
+ "aria-label"?: EmbeddedIconProps["iconDescription"];
+ className?: string;
}
-export interface ButtonProps extends SharedProps, InheritedButtonProps { }
+// this is split due to a typing issue with the specialized buttons (SecondaryButton, etc)
+interface ButtonKindProps {
+ kind?: ButtonKind; // required by has default value
+}
-export interface ButtonAnchorProps extends SharedProps, InheritedAnchorProps { }
+// these props are not passed to the general createElement call
+interface ButtonBaseIsolatedProps extends EmbeddedIconProps, EmbeddedTooltipProps {
+ hasIconOnly?: boolean;
+ // trying to type this just causes problems around inference, overload selection, and anon fn vs typed component references.
+ // if anon render props type is desired, import ButtonRenderIconRenderProps.
+ renderIcon?: any;
+ size?: ButtonSize;
+ /**
+ * @deprecated
+ */
+ small?: boolean;
+}
+type SafeProps = Omit
;
-export type AllButtonProps = ButtonAnchorProps | ButtonProps;
-declare const Button: React.RefForwardingComponent;
+interface ButtonBaseProps extends ButtonBaseIsolatedProps {
+ children?: React.ReactNode;
+ className?: string;
+ disabled?: boolean;
+}
+
+export interface ButtonDefaultProps extends ButtonBaseProps, ReactButtonAttr {
+ as?: undefined;
+ href?: undefined;
+}
+// alias for old type that used to be exported
+export type ButtonProps = ButtonDefaultProps;
+
+export interface ButtonAnchorProps extends ButtonBaseProps, Omit {
+ as?: undefined;
+ href: string;
+}
+
+export type ButtonIntrinsicProps = ButtonBaseProps &
+ SafeProps> & {
+ as: K;
+ };
+
+export type ButtonCustomComponentProps<
+ C extends React.JSXElementConstructor
+> = C extends React.JSXElementConstructor
+ ? ButtonBaseProps &
+ SafeProps & {
+ as: C;
+ }
+ : never;
+
+//
+// Note: TypeScript will try to select the best overload but this is not always easily predictable the more freedom the
+// generic types have or the more they overlap. If you're having difficulty with these types you can try reexporting the
+// component casted to your desired type.
+// ex:
+// import { Button } from "carbon-components-react"
+// export const DefaultButton = Button as React.FC;
+// export const AnchorButton = Button as React.FC;
+//
+// or just create a wrapper component.
+//
+declare function Button(props: ForwardRefProps): FCReturn;
+// tslint:disable:unified-signatures breaks certain usages
+declare function Button(props: ForwardRefProps): FCReturn;
+declare function Button(props: ForwardRefProps & ButtonKindProps>): FCReturn;
+declare function Button, R = unknown>(props: ForwardRefProps & ButtonKindProps>): FCReturn;
export default Button;
diff --git a/types/carbon-components-react/lib/components/DangerButton/DangerButton.d.ts b/types/carbon-components-react/lib/components/DangerButton/DangerButton.d.ts
index 0e7c4e1449..4a2b77faf0 100644
--- a/types/carbon-components-react/lib/components/DangerButton/DangerButton.d.ts
+++ b/types/carbon-components-react/lib/components/DangerButton/DangerButton.d.ts
@@ -1,10 +1,16 @@
import * as React from "react";
-import { ButtonProps } from "../Button";
+import {
+ ButtonAnchorProps,
+ ButtonDefaultProps,
+ ButtonIntrinsicProps,
+ ButtonCustomComponentProps,
+} from '../Button';
+import { FCReturn, FCProps } from '../../../typings/shared';
-interface InheritedProps extends Omit { }
-
-export interface DangerButtonProps extends InheritedProps { }
-
-declare const DangerButton: React.FC;
+declare function DangerButton(props: FCProps): FCReturn;
+// tslint:disable:unified-signatures breaks certain usages
+declare function DangerButton(props: FCProps): FCReturn;
+declare function DangerButton(props: FCProps>): FCReturn;
+declare function DangerButton>(props: FCProps>): FCReturn;
export default DangerButton;
diff --git a/types/carbon-components-react/lib/components/DataTable/TableBatchAction.d.ts b/types/carbon-components-react/lib/components/DataTable/TableBatchAction.d.ts
index 3bac419c51..eb8d9b026f 100644
--- a/types/carbon-components-react/lib/components/DataTable/TableBatchAction.d.ts
+++ b/types/carbon-components-react/lib/components/DataTable/TableBatchAction.d.ts
@@ -1,10 +1,4 @@
-import * as React from "react";
-import { ButtonProps } from "../Button";
+import Button from "../Button";
-interface InheritedProps extends ButtonProps { }
-
-export interface TableBatchActionProps extends InheritedProps { }
-
-declare const TableBatchAction: React.FC;
-
-export default TableBatchAction;
+// It's the same thing except it has different default props.
+export default Button;
diff --git a/types/carbon-components-react/lib/components/ModalWrapper/ModalWrapper.d.ts b/types/carbon-components-react/lib/components/ModalWrapper/ModalWrapper.d.ts
index 3923b320e1..2bec2b9024 100644
--- a/types/carbon-components-react/lib/components/ModalWrapper/ModalWrapper.d.ts
+++ b/types/carbon-components-react/lib/components/ModalWrapper/ModalWrapper.d.ts
@@ -1,5 +1,5 @@
import * as React from "react";
-import { ButtonProps } from "../Button";
+import { ButtonProps, ButtonKind } from '../Button';
import { ModalProps } from "../Modal";
type ExcludedModalProps = "onRequestClose" | "onRequestSubmit" | "open";
@@ -10,7 +10,7 @@ export interface TriggerProps {
buttonTriggerText?: ButtonProps["children"],
renderTriggerButtonIcon?: ButtonProps["renderIcon"],
triggerButtonIconDescription?: ButtonProps["iconDescription"],
- triggerButtonKind?: ButtonProps["kind"],
+ triggerButtonKind?: ButtonKind,
}
export interface ModalWrapperProps extends InheritedProps, TriggerProps {
diff --git a/types/carbon-components-react/lib/components/SecondaryButton/SecondaryButton.d.ts b/types/carbon-components-react/lib/components/SecondaryButton/SecondaryButton.d.ts
index b4f53dee70..84d1c9dc8c 100644
--- a/types/carbon-components-react/lib/components/SecondaryButton/SecondaryButton.d.ts
+++ b/types/carbon-components-react/lib/components/SecondaryButton/SecondaryButton.d.ts
@@ -1,10 +1,16 @@
import * as React from "react";
-import { ButtonProps } from "../Button";
+import {
+ ButtonAnchorProps,
+ ButtonDefaultProps,
+ ButtonIntrinsicProps,
+ ButtonCustomComponentProps,
+} from '../Button';
+import { FCReturn, FCProps } from '../../../typings/shared';
-interface InheritedProps extends Omit { }
-
-export interface SecondaryButtonProps extends InheritedProps { }
-
-declare const SecondaryButton: React.FC;
+declare function SecondaryButton(props: FCProps): FCReturn;
+// tslint:disable:unified-signatures breaks certain usages
+declare function SecondaryButton(props: FCProps): FCReturn;
+declare function SecondaryButton(props: FCProps>): FCReturn;
+declare function SecondaryButton>(props: FCProps>): FCReturn;
export default SecondaryButton;
diff --git a/types/carbon-components-react/lib/components/UIShell/HeaderMenu.d.ts b/types/carbon-components-react/lib/components/UIShell/HeaderMenu.d.ts
index 67857e279a..d174f0ddfb 100644
--- a/types/carbon-components-react/lib/components/UIShell/HeaderMenu.d.ts
+++ b/types/carbon-components-react/lib/components/UIShell/HeaderMenu.d.ts
@@ -1,5 +1,5 @@
import * as React from "react";
-import { ReactAttr, ForwardRefRefType, FCReturn, FCProps } from "../../../typings/shared";
+import { ReactAttr, FCReturn } from '../../../typings/shared';
interface InheritedProps {
"aria-label"?: ReactAttr["aria-label"],
@@ -11,14 +11,12 @@ interface InheritedProps {
export interface HeaderMenuProps