When you create a function in TypeScript which uses a generic type parameter, you must specify the type parameter when invoking the function (unless it can be inferred from an argument).
A React function component is just a function, so when you invoke the function component in your JSX, you must still supply the generic type parameter in order for the compiler to have that type information.
In the code shown in the error message of your question, you don't do that, so the event type is unknown to the compiler:
const reactElement = <Component onClick={(e) => e}/>; /*
~
Parameter 'e' implicitly has an 'any' type.(7006) */
By supplying a valid generic type parameter for the element, the compiler will infer the event type:
const reactElement = <Component<'div'> onClick={(e) => e}/>; // Ok!
//^? (parameter) e: React.MouseEvent<HTMLDivElement, MouseEvent>
In the component you showed, the as prop should probably not be optional. When you supply the as prop, the compiler will infer the generic from its value:
const reactElement = <Component as="div" onClick={(e) => e}/>; // Ok!
//^? (parameter) e: React.MouseEvent<HTMLDivElement, MouseEvent>
Code in TypeScript Playground
If you must use a pattern of accepting the as prop optionally (with a default element type of "button" when it is not provided, you can use a function overload signature to make that clear to the compiler:
TS Playground
import {
default as React,
type ComponentPropsWithoutRef,
type ElementType,
type ReactElement,
} from 'react';
function Component <T extends ElementType>({as, ...rest}: { as: T } & ComponentPropsWithoutRef<T>): ReactElement;
function Component ({as, ...rest}: { as?: never } & ComponentPropsWithoutRef<'button'>): ReactElement;
function Component <T extends ElementType>({as, ...rest}: { as?: T } & ComponentPropsWithoutRef<T>) {
const Tag = as ?? 'button';
return <Tag {...rest} />;
}
const reactElement1 = <Component onClick={(e) => e}/>;
//^? (parameter) e: React.MouseEvent<HTMLButtonElement, MouseEvent>
const reactElement2 = <Component as="div" onClick={(e) => e}/>;
//^? (parameter) e: React.MouseEvent<HTMLDivElement, MouseEvent>