Ver código fonte

Unexpected any types replaced (#160)

* Any types replaced

* No console rule disabled
Guzel738 4 anos atrás
pai
commit
3c843e1266

+ 2 - 1
kafka-ui-react-app/.eslintrc.json

@@ -28,7 +28,8 @@
     "prettier/prettier": "error",
     "@typescript-eslint/explicit-module-boundary-types": "off",
     "jsx-a11y/label-has-associated-control": "off",
-    "import/prefer-default-export": "off"
+    "import/prefer-default-export": "off",
+    "@typescript-eslint/no-explicit-any": "error"
   },
   "overrides": [
     {

+ 11 - 7
kafka-ui-react-app/src/components/Topics/Details/Messages/Messages.tsx

@@ -38,8 +38,8 @@ interface FilterProps {
   partition: TopicMessage['partition'];
 }
 
-function usePrevious(value: any) {
-  const ref = useRef();
+function usePrevious(value: Date | null) {
+  const ref = useRef<Date | null>();
   useEffect(() => {
     ref.current = value;
   });
@@ -73,7 +73,8 @@ const Messages: React.FC<Props> = ({
     Partial<TopicMessageQueryParams>
   >({ limit: 100 });
   const [debouncedCallback] = useDebouncedCallback(
-    (query: any) => setQueryParams({ ...queryParams, ...query }),
+    (query: Partial<TopicMessageQueryParams>) =>
+      setQueryParams({ ...queryParams, ...query }),
     1000
   );
 
@@ -98,7 +99,7 @@ const Messages: React.FC<Props> = ({
     );
   }, [messages, partitions]);
 
-  const getSeekToValuesForPartitions = (partition: any) => {
+  const getSeekToValuesForPartitions = (partition: Option) => {
     const foundedValues = filterProps.find(
       (prop) => prop.partition === partition.value
     );
@@ -178,7 +179,7 @@ const Messages: React.FC<Props> = ({
     return format(date, 'yyyy-MM-dd HH:mm:ss');
   };
 
-  const getMessageContentBody = (content: any) => {
+  const getMessageContentBody = (content: Record<string, unknown>) => {
     try {
       const contentObj =
         typeof content !== 'object' ? JSON.parse(content) : content;
@@ -226,7 +227,7 @@ const Messages: React.FC<Props> = ({
     });
   };
 
-  const filterOptions = (options: Option[], filter: any) => {
+  const filterOptions = (options: Option[], filter: string) => {
     if (!filter) {
       return options;
     }
@@ -256,7 +257,10 @@ const Messages: React.FC<Props> = ({
                 <td style={{ width: 150 }}>{message.offset}</td>
                 <td style={{ width: 100 }}>{message.partition}</td>
                 <td key={Math.random()} style={{ wordBreak: 'break-word' }}>
-                  {getMessageContentBody(message.content)}
+                  {message.content &&
+                    getMessageContentBody(
+                      message.content as Record<string, unknown>
+                    )}
                 </td>
               </tr>
             ))}

+ 7 - 1
kafka-ui-react-app/src/redux/store/configureStore/dev.ts

@@ -2,11 +2,17 @@ import { createStore, applyMiddleware, compose } from 'redux';
 import thunk from 'redux-thunk';
 import rootReducer from '../../reducers';
 
+declare global {
+  interface Window {
+    __REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
+  }
+}
+
 export default () => {
   const middlewares = [thunk];
 
   const composeEnhancers =
-    (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
+    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
 
   const enhancer = composeEnhancers(applyMiddleware(...middlewares));
 

+ 1 - 0
kafka-ui-react-app/src/serviceWorker.ts

@@ -9,6 +9,7 @@
 
 // To learn more about the benefits of this model and instructions on how to
 // opt-in, read https://bit.ly/CRA-PWA
+/* eslint-disable no-console */
 
 const isLocalhost = Boolean(
   window.location.hostname === 'localhost' ||