Skip to content

Property 'ref' does not exist on type 'IntrinsicAttributes & FastOmit<ViewProps, never>'. #4143

Closed

Description

@lucasoliveiraw00

Environment

System:

  • OS: macOS 13.4.1
  • CPU: (8) arm64 Apple M1
  • Memory: 105.88 MB / 16.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
  • Yarn: 1.22.19 - /opt/homebrew/bin/yarn
  • npm: 9.5.1 - /opt/homebrew/bin/npm

npmPackages:

  • styled-components: ^6.0.7 => 6.0.7

Reproduction

codesandbox

print

Activity

  1. Dimasprog commented on Sep 22, 2023

    @Dimasprog

    Any solutions?

  2. wr-lhiggitt commented on Sep 27, 2023

    @wr-lhiggitt

    I am also having this issue. It appears this is an issue for V6 versions and makes styled-components V6 unusable for react-native.

  3. wr-lhiggitt commented on Sep 27, 2023

    @wr-lhiggitt

    FYI - I've found that if you use styled as a function rather than using the static properties, refs seem to type properly:

    This example does not work:

    import React, { useRef } from 'react';
    import { TextInput } from 'react-native';
    import styled from 'styled-components/native';
    
    const StyledTextInput = styled.TextInput``;
    
    function App(): JSX.Element {
      const ref = useRef(null);
    
      return (
          <StyledTextInput
            ref={ref} //  Type '{ ref: MutableRefObject<null>; }' is not assignable to type 'IntrinsicAttributes & FastOmit<Substitute<FastOmit<TextInputProps, never>, FastOmit<{}, never>>, keyof ExecutionProps> & FastOmit<...> & { ...; }'
          />
      );
    }

    This example does work:

    import React, { useRef } from 'react';
    import { TextInput } from 'react-native';
    import styled from 'styled-components/native';
    
    const StyledTextInput = styled(TextInput)``;
    
    function App(): JSX.Element {
      const ref = useRef(null);
    
      return (
          <StyledTextInput
            ref={ref}
          />
      );
    }
  4. nazmeln commented on Oct 17, 2023

    @nazmeln
    Contributor

    +1

  5. Orrin-Manning commented on Oct 31, 2023

    @Orrin-Manning

    +1

  6. OliveiraCleidson commented on Nov 2, 2023

    @OliveiraCleidson

    FYI - I've found that if you use styled as a function rather than using the static properties, refs seem to type properly:

    This example does not work:

    import React, { useRef } from 'react';
    import { TextInput } from 'react-native';
    import styled from 'styled-components/native';
    
    const StyledTextInput = styled.TextInput``;
    
    function App(): JSX.Element {
      const ref = useRef(null);
    
      return (
          <StyledTextInput
            ref={ref} //  Type '{ ref: MutableRefObject<null>; }' is not assignable to type 'IntrinsicAttributes & FastOmit<Substitute<FastOmit<TextInputProps, never>, FastOmit<{}, never>>, keyof ExecutionProps> & FastOmit<...> & { ...; }'
          />
      );
    }

    This example does work:

    import React, { useRef } from 'react';
    import { TextInput } from 'react-native';
    import styled from 'styled-components/native';
    
    const StyledTextInput = styled(TextInput)``;
    
    function App(): JSX.Element {
      const ref = useRef(null);
    
      return (
          <StyledTextInput
            ref={ref}
          />
      );
    }

    Using styled(TextInput) worked for me, but this doesn't smell good

  7. hadnet commented on Nov 24, 2023

    @hadnet

    Same here. TS now throws Type 'RefObject<TextInputProps & { value: string; setNativeProps: ({ text }: { text: string; }) => void; focus: () => void; }>' is not assignable to type 'Ref<TextInput> | undefined' when using something like this:

    export const Input = styled.TextInput.attrs(({theme}) => ({
      placeholderTextColor: theme.input.color,
    }))<InputProps>`
  8. t0ma5h commented on Apr 25, 2024

    @t0ma5h

    Same issue.
    Using styled(View) insted of styled.View works though.

  9. gburatti commented on Dec 5, 2024

    @gburatti

    +1

  10. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor

    Fixed — added React.RefAttributes to the PolymorphicComponent overload's call signature so ref is accepted on both web and native styled components. Previously, the polymorphic overload lacked ref, and TS would report the error from that overload instead of falling through to the base ForwardRefExoticComponent signature.

  11. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor

    This fix is available in [email protected]. Please try it and report any issues:

    npm install [email protected]
    
  12. wojtekmaj commented on Mar 19, 2026

    @wojtekmaj

    I confirm that [email protected] fixed it for me.

    Just maybe a notable mention that I had to clean up the workaround I used before:

    import styled from 'styled-components/native';
    
    -import type { View } from 'react-native';
    -
    -const MyView = styled.View<{ active?: boolean; ref?: React.Ref<View | null> }>``;
    +const MyView = styled.View<{ active?: boolean }>``;
    
    // error TS7006: Parameter 'ref' implicitly has an 'any' type.
    <MyView active ref={(ref) => {}} />;
    

    Other than that, no regressions on 80,000 LoC codebase.

  13. FreTimmerman commented on Jun 4, 2026

    @FreTimmerman

    i can also confirm that [email protected] fixed it for me

    however, the actual (non-prerelease) 6.4.0 and newer don't have this fix? it seems it hasn't been merged in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions