Property ‘scrollintoview’ does not exist on type ‘never’.ts(2339)

Explanation:

The error message “Property ‘scrollintoview’ does not exist on type ‘never’.” is a Typescript error message that indicates that the compiler is unable to find the ‘scrollintoview’ property on a variable or object of type ‘never’.

This error usually occurs when you are trying to access or use the ‘scrollintoview’ property on a variable or object that has been inferred by the compiler as type ‘never’.

‘never’ is a bottom type in TypeScript, meaning it represents a type that cannot occur. It usually happens when the compiler infers that a variable or expression is of type ‘never’ because it cannot determine any other possible type.

Example:

// Example 1
   function getElement(): never {
      throw new Error("Function always throws an error");
   }

   const element = getElement();
   element.scrollintoview; // Error: Property 'scrollintoview' does not exist on type 'never'.

In this example, we have a function getElement() that always throws an error, which means it never returns. Therefore, the inferred return type is ‘never’.

When we try to access the scrollintoview property on the variable element, it results in a Typescript error because the ‘scrollintoview’ property does not exist on type ‘never’.

// Example 2
   let value: unknown;
   if (typeof value !== "undefined" && value !== null) {
      value.scrollintoview; // Error: Property 'scrollintoview' does not exist on type 'never' or 'unknown'.
   }

In this example, we have a variable value with the type ‘unknown’. Since ‘unknown’ is a supertype of all types, including ‘never’, accessing the scrollintoview property on the value variable results in a Typescript error.

To solve this error, you need to ensure that the variable or object on which you are trying to access the ‘scrollintoview’ property is of a relevant type that actually has this property. It may require checking the type or ensuring the variable is assigned a proper value that has the ‘scrollintoview’ property.

Leave a comment