-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix complex unions TS error with as prop (#730)
* hallelujah * that's a better spot
- Loading branch information
1 parent
a2f2330
commit 0448169
Showing
11 changed files
with
17,301 additions
and
7 deletions.
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
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,25 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier/@typescript-eslint", | ||
"plugin:prettier/recommended" | ||
], | ||
"plugins": ["react", "@typescript-eslint", "prettier"], | ||
"env": { | ||
"browser": true, | ||
"jasmine": true, | ||
"jest": true | ||
}, | ||
"rules": { | ||
"prettier/prettier": ["error", { "singleQuote": true }] | ||
}, | ||
"settings": { | ||
"react": { | ||
"pragma": "React", | ||
"version": "detect" | ||
} | ||
}, | ||
"parser": "@typescript-eslint/parser" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
import * as Stitches from '@stitches/react'; | ||
import * as React from 'react'; | ||
export const { config, styled } = Stitches.createStitches({ | ||
utils: { | ||
/** util to do stuff */ | ||
ml: (value) => ({ marginLeft: value }), | ||
}, | ||
theme: { | ||
colors: { | ||
red100: '#ff0000', | ||
}, | ||
}, | ||
}); | ||
export const Text = styled('span', {}); | ||
const DEFAULT_TAG = 'h1'; | ||
const Heading = React.forwardRef((props, forwardedRef) => { | ||
return (<> | ||
{/* types here will be fast */} | ||
<Text as={DEFAULT_TAG} onClick={(e) => { console.log(e.altKey); }} ref={forwardedRef}/> | ||
<Text onClick={(e) => { console.log(e.altKey); }} ref={forwardedRef} css={{ backgroundColor: '$red100', backgroundClip: 'border-box' }}/> | ||
<Text onClick={(e) => { console.log(e.altKey); }} ref={forwardedRef} css={{ backgroundColor: '$red100' }}/> | ||
<Text as="b" onClick={(e) => { console.log(e.altKey); }} ref={forwardedRef} css={{ ...props.css, backgroundColor: '$red100', padding: 'initial' }}/> | ||
<Text as="div" onClick={(e) => { console.log(e.altKey); }} css={{ ...props.css, backgroundColor: '$red100', background: 'red', paddingLeft: 'initial' }}/> | ||
{/* | ||
types here will be correct but autocompletion is going to be painfully slow when you add a new prop. | ||
This is the only case where the autocompletion is slow | ||
*/} | ||
<Text as={DEFAULT_TAG} {...props} onClick={(e) => { console.log(e.altKey); }} ref={forwardedRef}/> | ||
</>); | ||
}); | ||
const App = () => { | ||
// when consuming the component it should be very fast too | ||
return <Heading css={{ backgroundColor: '$red100', padding: 'inherit' }}/>; | ||
}; |
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,44 @@ | ||
import * as Stitches from '@stitches/react' | ||
import * as React from 'react' | ||
|
||
export const { config, styled } = Stitches.createStitches({ | ||
utils: { | ||
/** util to do stuff */ | ||
ml: (value: Stitches.PropertyValue<'margin'>) => ({ marginLeft: value }), | ||
}, | ||
theme: { | ||
colors: { | ||
red100: '#ff0000', | ||
}, | ||
}, | ||
}) | ||
|
||
export type StitchesCss = Stitches.CSS<typeof config> | ||
|
||
export const Text = styled('span', { | ||
background: '$red100' | ||
}) | ||
|
||
|
||
const DEFAULT_TAG = 'h1' | ||
|
||
export type HeadingProps = React.ComponentProps<typeof DEFAULT_TAG> & { css?: StitchesCss } | ||
|
||
const Heading = React.forwardRef<React.ElementRef<typeof DEFAULT_TAG>, HeadingProps>((props, forwardedRef) => { | ||
return ( | ||
<> | ||
{/* types here will be fast */} | ||
<Text as={DEFAULT_TAG} onClick={(e) => {console.log(e.altKey)}} ref={forwardedRef} /> | ||
<Text onClick={(e) => {console.log(e.altKey)}} ref={forwardedRef} css={{backgroundColor: '$red100', backgroundClip: 'border-box', ml: 'auto'}}/> | ||
<Text onClick={(e) => {console.log(e.altKey)}} ref={forwardedRef} css={{ backgroundColor: '$red100'}} /> | ||
<Text as="b" onClick={(e) => {console.log(e.altKey)}} ref={forwardedRef} css={{ ...props.css, backgroundColor: '$red100', padding: 'initial' }} /> | ||
<Text as="div" onClick={(e) => {console.log(e.altKey)}} css={{ ...props.css, backgroundColor: '$red100', background: 'red', paddingLeft: 'initial'}} /> | ||
<Text as={DEFAULT_TAG} {...props} onClick={(e) => {console.log(e.altKey)}} ref={forwardedRef} /> | ||
</> | ||
) | ||
}) | ||
|
||
const App = () => { | ||
// when consuming the component it should be very fast too | ||
return <Heading css={{ backgroundColor: '$red100', padding: 'inherit'}} /> | ||
} |
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,27 @@ | ||
{ | ||
"name": "@stitches/test", | ||
"version": "1.0.0-canary.7", | ||
"type": "module", | ||
"files": [ | ||
"dist/*.cjs", | ||
"dist/*.js", | ||
"dist/*.map", | ||
"dist/*.mjs", | ||
"types/*.d.ts" | ||
], | ||
"devDependencies": { | ||
"@stitches/react": "^1.0.0-canary.10", | ||
"@typescript-eslint/eslint-plugin": "^1.6.0", | ||
"@typescript-eslint/parser": "^1.6.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-config-react": "^1.1.7", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"prettier": "^1.16.4", | ||
"typescript": "^4.3.5", | ||
"react": "17.0.2" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@radix-ui/react-polymorphic": "0.0.13" | ||
} | ||
} |
Oops, something went wrong.