dosubot[bot] commented on issue #37069:
URL: https://github.com/apache/superset/issues/37069#issuecomment-3742467781

   <!-- Answer -->
   Your TypeScript errors are because updates is declared as an untyped {} 
object, so TypeScript doesn't allow string indexing or assignment of 
DataMaskWithId values. To fix all three errors (TS7053, TS2322, TS2345), 
explicitly type updates as Record<string, DataMaskWithId> in your 
handleClearAll function. Here’s how you should declare and use it:
   
   ```ts
   const updates: Record<string, DataMaskWithId> = {};
   nativeFilterValues.forEach(filter => {
     const { id } = filter;
     if (dataMaskSelected[id]) {
       updates[id] = {
         ...dataMaskSelected[id],
         filterState: {
           ...dataMaskSelected[id].filterState,
           value: null,
         },
         extraFormData: {},
       };
       newClearAllTriggers[id] = true;
     }
   });
   
   setDataMaskSelected(draft => {
     Object.entries(updates).forEach(([id, mask]) => {
       draft[id] = mask;
     });
   });
   
   Object.entries(updates).forEach(([id, mask]) => {
     dispatch(updateDataMask(id, mask));
   });
   ```
   
   This ensures TypeScript knows updates is a dictionary of DataMaskWithId, so 
string indexing and assignments are valid, and the masks are the correct type 
for both Immer and Redux dispatch. This pattern matches how Superset’s own code 
handles these types 
([reference](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx#L149-L305)).
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/960680c3-f0e8-4d50-b4e6-5f6212611d66?feedback_type=other)</sup>
   
   [![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Your%20TypeScript%20errors%20are%20because%20updates%20is%20declared%20as%20an%20untyped%20%7B%7D%20object%2C%20so%20TypeScript%20doesn%27t%20allow%20string%20indexing%20or%20assignment%20of%20DataMaskWithId%20values.%20To%20fix%20all%20three%20errors%20%28TS7053%2C%20TS2322%2C%20TS2345%29%2C%20explicitly%20type%20updates%20as%20Record%3Cstring%2C%20DataMaskWithId%3E%20in%20your%20handleClearAll%20function.%20Here%E2%80%99s%20how%20you%20should%20declare%20and%20use%20it%3A%0A%0A%60%60%60ts%0Aconst%20updates%3A%20Record%3Cstring%2C%20DataMaskWithId%3E%20%3D%20%7B%7D%3B%0AnativeFilterValues.forEach%28filter%20%3D%3E%20%7B%0A%20%20const%20%7B%20id%20%7D%20%3D%20filter%3B%0A%20%20if%20%28dataMaskSelected%5Bid%5D%29%20%7B%0A%20%20%20%20updates%5Bid%5D%
 
20%3D%20%7B%0A%20%20%20%20%20%20...dataMaskSelected%5Bid%5D%2C%0A%20%20%20%20%20%20filterState%3A%20%7B%0A%20%20%20%20%20%20%20%20...dataMaskSelected%5Bid%5D.filterState%2C%0A%20%20%20%20%20%20%20%20value%3A%20null%2C%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20extraFormData%3A%20%7B%7D%2C%0A%20%20%20%20%7D%3B%0A%20%20%20%20newClearAllTriggers%5Bid%5D%20%3D%20true%3B%0A%20%20%7D%0A%7D%29%3B%0A%0AsetDataMaskSelected%28draft%20%3D%3E%20%7B%0A%20%20Object.entries%28updates%29.forEach%28%28%5Bid%2C%20mask%5D%29%20%3D%3E%20%7B%0A%20%20%20%20draft%5Bid%5D%20%3D%20mask%3B%0A%20%20%7D%29%3B%0A%7D%29%3B%0A%0AObject.entries%28updates%29.forEach%28%28%5Bid%2C%20mask%5D%29%20%3D%3E%20%7B%0A%20%20dispatch%28updateDataMask%28id%2C%20mask%29%29%3B%0A%7D%29%3B%0A%60%60%60%0A%0AThis%20ensures%20TypeScript%20knows%20updates%20is%20a%20dictionary%20of%20DataMaskWithId%2C%20so%20string%20indexing%20and%20assignments%20are%20valid%2C%20and%20the%20masks%20are%20the%20correct%20type%20for%20both%20Imm
 
er%20and%20Redux%20dispatch.%20This%20pattern%20matches%20how%20Superset%E2%80%99s%20own%20code%20handles%20these%20types%20%28%5Breference%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx%23L149-L305%29%29.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/37069)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to