-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// @charcoal-ui/react is not listed as a dependency so only use the type | ||
import type { Button as ButtonType } from '@charcoal-ui/react' | ||
import styled from 'styled-components' | ||
|
||
declare const Button: typeof ButtonType | ||
|
||
const Custom = ({ custom }: { custom: string }) => <>{custom}</> | ||
const CustomGeneric = <C extends string>({ custom }: { custom: C }) => ( | ||
<>{custom}</> | ||
) | ||
|
||
const StyledButton = styled(Button)`` | ||
const StyledButtonAsButton = styled(Button<'button'>)`` | ||
const StyledButtonA = styled(Button<'a'>)`` | ||
const StyledButtonCustom = styled(Button<typeof Custom>)`` | ||
const StyledButtonCustomAsButton = styled( | ||
Button<typeof Custom> | ||
)`` as typeof Button | ||
const StyledButtonCustomGeneric = styled(Button<typeof CustomGeneric>)`` | ||
const StyledButtonCustomGenericFoo = styled( | ||
Button<typeof CustomGeneric<'foo'>> | ||
)`` | ||
|
||
// for type test only | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function Tests() { | ||
return ( | ||
<> | ||
<StyledButton /> | ||
<StyledButton type="button" disabled /> | ||
{/* @ts-expect-error Property 'href' does not exist on type */} | ||
<StyledButton href="" /> | ||
|
||
<StyledButtonAsButton type="button" disabled /> | ||
{/* @ts-expect-error Property 'href' does not exist on type */} | ||
<StyledButtonAsButton href="" /> | ||
|
||
<StyledButtonA component="a" href="#" /> | ||
{/* @ts-expect-error Property 'component' is missing */} | ||
<StyledButtonA href="#" /> | ||
{/* @ts-expect-error Property 'disabled' does not exist on type */} | ||
<StyledButtonA disabled /> | ||
{/* @ts-expect-error Type '"button"' is not assignable to type '"a"' */} | ||
<StyledButtonA component="button" href="" /> | ||
|
||
<StyledButtonCustom component={Custom} custom="" /> | ||
{/* @ts-expect-error Property 'component' is missing */} | ||
<StyledButtonCustom custom="" /> | ||
{/* @ts-expect-error Type 'string' is not assignable */} | ||
<StyledButtonCustom component="a" custom="" /> | ||
|
||
<StyledButtonCustomAsButton<'a'> component="a" href="#" /> | ||
<StyledButtonCustomAsButton<typeof CustomGeneric<'bar'>> | ||
component={CustomGeneric} | ||
custom="bar" | ||
/> | ||
<StyledButtonCustomAsButton component="a" href="#" /> | ||
{/* @ts-expect-error Property 'custom' does not exist on type */} | ||
<StyledButtonCustomAsButton custom="" /> | ||
{/* @ts-expect-error Type 'href' is not assignable */} | ||
<StyledButtonCustomAsButton<'button'> href="#" /> | ||
|
||
<StyledButtonCustomGeneric component={CustomGeneric} custom="" /> | ||
|
||
<StyledButtonCustomGenericFoo component={CustomGeneric} custom="foo" /> | ||
<StyledButtonCustomGenericFoo | ||
component={CustomGeneric<'foo'>} | ||
custom="foo" | ||
/> | ||
<StyledButtonCustomGenericFoo | ||
/* @ts-expect-error Type '"foo"' is not assignable to type '"bar"' */ | ||
component={CustomGeneric<'bar'>} | ||
custom="foo" | ||
/> | ||
{/* @ts-expect-error '""' is not assignable to type '"foo"' */} | ||
<StyledButtonCustomGenericFoo custom="" /> | ||
</> | ||
) | ||
} |