1- import  *  as  React  from  'react' 
2- import  { 
3-   getDefaultShouldForwardProp , 
4-   composeShouldForwardProps 
5-   /* 
6-   type StyledOptions, 
7-   type CreateStyled, 
8-   type PrivateStyledComponent, 
9-   type StyledElementType 
10-   */ 
11- }  from  './utils' 
12- import  {  withEmotionCache ,  ThemeContext  }  from  '@emotion/react' 
13- import  isDevelopment  from  '#is-development' 
141import  isBrowser  from  '#is-browser' 
2+ import  isDevelopment  from  '#is-development' 
3+ import  {  Theme ,  ThemeContext ,  withEmotionCache  }  from  '@emotion/react' 
4+ import  {  Interpolation ,  serializeStyles  }  from  '@emotion/serialize' 
5+ import  {  useInsertionEffectAlwaysWithSyncFallback  }  from  '@emotion/use-insertion-effect-with-fallbacks' 
156import  { 
7+   EmotionCache , 
168  getRegisteredStyles , 
179  insertStyles , 
18-   registerStyles 
10+   registerStyles , 
11+   SerializedStyles 
1912}  from  '@emotion/utils' 
20- import  {  serializeStyles  }  from  '@emotion/serialize' 
21- import  {  useInsertionEffectAlwaysWithSyncFallback  }  from  '@emotion/use-insertion-effect-with-fallbacks' 
13+ import  *  as  React  from  'react' 
14+ import  { 
15+   CreateStyled , 
16+   ElementType , 
17+   StyledComponent , 
18+   StyledOptions 
19+ }  from  './types' 
20+ import  {  composeShouldForwardProps ,  getDefaultShouldForwardProp  }  from  './utils' 
21+ export  type  { 
22+   ComponentSelector , 
23+   ArrayInterpolation , 
24+   CSSObject , 
25+   FunctionInterpolation , 
26+   Interpolation 
27+ }  from  '@emotion/serialize' 
2228
2329const  ILLEGAL_ESCAPE_SEQUENCE_ERROR  =  `You have illegal escape sequence in your template literal, most likely inside content's property value. 
2430Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';". 
2531You can read more about this here: 
2632https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences` 
2733
28- const  Insertion  =  ( {  cache,  serialized,  isStringTag } )  =>  { 
34+ const  Insertion  =  ( { 
35+   cache, 
36+   serialized, 
37+   isStringTag
38+ } : { 
39+   cache : EmotionCache 
40+   serialized : SerializedStyles 
41+   isStringTag : boolean 
42+ } )  =>  { 
2943  registerStyles ( cache ,  serialized ,  isStringTag ) 
3044
3145  const  rules  =  useInsertionEffectAlwaysWithSyncFallback ( ( )  => 
@@ -52,10 +66,7 @@ const Insertion = ({ cache, serialized, isStringTag }) => {
5266  return  null 
5367} 
5468
55- let  createStyled  /*: CreateStyled */  =  ( 
56-   tag  /*: any */ , 
57-   options  /* ?: StyledOptions */ 
58- )  =>  { 
69+ const  createStyled  =  ( tag : ElementType ,  options ?: StyledOptions )  =>  { 
5970  if  ( isDevelopment )  { 
6071    if  ( tag  ===  undefined )  { 
6172      throw  new  Error ( 
@@ -66,8 +77,8 @@ let createStyled /*: CreateStyled */ = (
6677  const  isReal  =  tag . __emotion_real  ===  tag 
6778  const  baseTag  =  ( isReal  &&  tag . __emotion_base )  ||  tag 
6879
69-   let  identifierName 
70-   let  targetClassName 
80+   let  identifierName :  string   |   undefined 
81+   let  targetClassName :  string   |   undefined 
7182  if  ( options  !==  undefined )  { 
7283    identifierName  =  options . label 
7384    targetClassName  =  options . target 
@@ -78,9 +89,11 @@ let createStyled /*: CreateStyled */ = (
7889    shouldForwardProp  ||  getDefaultShouldForwardProp ( baseTag ) 
7990  const  shouldUseAs  =  ! defaultShouldForwardProp ( 'as' ) 
8091
81-   /* return function<Props>(): PrivateStyledComponent<Props> { */ 
8292  return  function  ( )  { 
83-     let  args  =  arguments 
93+     // eslint-disable-next-line prefer-rest-params 
94+     let  args  =  arguments  as  any  as  Array < 
95+       TemplateStringsArray  |  Interpolation < Theme > 
96+     > 
8497    let  styles  = 
8598      isReal  &&  tag . __emotion_styles  !==  undefined 
8699        ? tag . __emotion_styles . slice ( 0 ) 
@@ -89,29 +102,35 @@ let createStyled /*: CreateStyled */ = (
89102    if  ( identifierName  !==  undefined )  { 
90103      styles . push ( `label:${ identifierName }  ) 
91104    } 
92-     if  ( args [ 0 ]  ==  null  ||  args [ 0 ] . raw  ===  undefined )  { 
105+     if  ( 
106+       args [ 0 ]  ==  null  || 
107+       ( args [ 0 ]  as  TemplateStringsArray ) . raw  ===  undefined 
108+     )  { 
109+       // eslint-disable-next-line prefer-spread 
93110      styles . push . apply ( styles ,  args ) 
94111    }  else  { 
95-       if  ( isDevelopment  &&  args [ 0 ] [ 0 ]  ===  undefined )  { 
112+       const  templateStringsArr  =  args [ 0 ]  as  TemplateStringsArray 
113+       if  ( isDevelopment  &&  templateStringsArr [ 0 ]  ===  undefined )  { 
96114        console . error ( ILLEGAL_ESCAPE_SEQUENCE_ERROR ) 
97115      } 
98-       styles . push ( args [ 0 ] [ 0 ] ) 
116+       styles . push ( templateStringsArr [ 0 ] ) 
99117      let  len  =  args . length 
100118      let  i  =  1 
101119      for  ( ;  i  <  len ;  i ++ )  { 
102-         if  ( isDevelopment  &&  args [ 0 ] [ i ]  ===  undefined )  { 
120+         if  ( isDevelopment  &&  templateStringsArr [ i ]  ===  undefined )  { 
103121          console . error ( ILLEGAL_ESCAPE_SEQUENCE_ERROR ) 
104122        } 
105-         styles . push ( args [ i ] ,  args [ 0 ] [ i ] ) 
123+         styles . push ( args [ i ] ,  templateStringsArr [ i ] ) 
106124      } 
107125    } 
108126
109-     const  Styled  /*: PrivateStyledComponent<Props> */  =  withEmotionCache ( 
110-       ( props ,  cache ,  ref )  =>  { 
111-         const  FinalTag  =  ( shouldUseAs  &&  props . as )  ||  baseTag 
127+     const  Styled : ElementType  =  withEmotionCache ( 
128+       ( props : Record < string ,  unknown > ,  cache ,  ref )  =>  { 
129+         const  FinalTag  =  ( ( shouldUseAs  &&  props . as )  || 
130+           baseTag )  as  React . ElementType 
112131
113132        let  className  =  '' 
114-         let  classInterpolations  =  [ ] 
133+         let  classInterpolations :  Interpolation < Theme > [ ]  =  [ ] 
115134        let  mergedProps  =  props 
116135        if  ( props . theme  ==  null )  { 
117136          mergedProps  =  { } 
@@ -146,7 +165,7 @@ let createStyled /*: CreateStyled */ = (
146165            ? getDefaultShouldForwardProp ( FinalTag ) 
147166            : defaultShouldForwardProp 
148167
149-         let  newProps  =  { } 
168+         let  newProps :  Record < string ,   unknown >  =  { } 
150169
151170        for  ( let  key  in  props )  { 
152171          if  ( shouldUseAs  &&  key  ===  'as' )  continue 
@@ -171,7 +190,7 @@ let createStyled /*: CreateStyled */ = (
171190          </ > 
172191        ) 
173192      } 
174-     ) 
193+     )   as   StyledComponent < any ,   any ,   any > 
175194
176195    Styled . displayName  = 
177196      identifierName  !==  undefined 
@@ -196,20 +215,20 @@ let createStyled /*: CreateStyled */ = (
196215        return  `.${ targetClassName }  
197216      } 
198217    } ) 
199- 
200-     Styled . withComponent  =  ( 
201-       nextTag  /*: StyledElementType<Props> */ , 
202-       nextOptions  /* ?: StyledOptions */ 
218+     ; ( Styled  as  any ) . withComponent  =  ( 
219+       nextTag : ElementType , 
220+       nextOptions : StyledOptions 
203221    )  =>  { 
204-       return  createStyled ( nextTag ,  { 
222+       const   newStyled   =  createStyled ( nextTag ,  { 
205223        ...options , 
206224        ...nextOptions , 
207225        shouldForwardProp : composeShouldForwardProps ( Styled ,  nextOptions ,  true ) 
208-       } ) ( ...styles ) 
226+       } ) 
227+       return  ( newStyled  as  any ) ( ...styles ) 
209228    } 
210229
211230    return  Styled 
212231  } 
213232} 
214233
215- export  default  createStyled 
234+ export  default  createStyled   as   CreateStyled 
0 commit comments