fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[BLOCKED] Support `data-xxx` on v9 component props type

Open YuanboXue-Amber opened this issue 2 years ago • 11 comments

Library

React Components / v9 (@fluentui/react-components)

Describe the feature that you would like added

Hi, I'm trying to use props['data-xxx'] (where props has type ButtonProps) and getting TS errors. Please support data-xxx on component props.

For example, the below code will give TS error:

Element implicitly has an 'any' type because expression of type '"data-test"' can't be used to index type 'ButtonProps'. Property 'data-test' does not exist on type 'ButtonProps'.ts(7053)

import { Button, ButtonProps } from "@fluentui/react-components"; 
const ButtonExample = (props: ButtonProps) => {
  console.log(props["data-test"]); // TS error here
  return <Button {...props}>Example</Button>;
};
export const Example = () => (
  <ButtonExample data-test="true">Example</ButtonExample>
);

Have you discussed this feature with our team

@layershifter @Hotell

Validations

  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

YuanboXue-Amber avatar May 17 '22 11:05 YuanboXue-Amber

@behowell can you please check this? @layershifter also has more context on this.

tudorpopams avatar Aug 08 '22 17:08 tudorpopams

This should be fixable by allowing any prop that starts with data-, e.g.:

Record<`data-${string}`, unknown>

However, it looks like this requires TypeScript 4.4+ to work: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#symbol-and-template-string-pattern-index-signatures . Our repo is currently on TypeScript 4.3.

behowell avatar Sep 02 '22 00:09 behowell

It looks like it's not possible to add support for this for clients that are on TypeScript 4.4 yet. Our TypeScript minbar is 3.9, and adding a template literal type fails to compile on 3.9 (see the build failure on the Draft PR: https://github.com/microsoft/fluentui/pull/24646).

I'm going to mark this as Blocked for now. We can add support once:

behowell avatar Sep 02 '22 23:09 behowell

Heyy, bumping this up. I found out TMP has on going process of upgrading typescript from 4.3 to 4.9 (feature 2759283). Would be nice if we catch up :)

YuanboXue-Amber avatar Jan 31 '23 20:01 YuanboXue-Amber

As of this morning TMP moved to 4.9.5. 🎉 Hope this helps to raise the min.

Hirse avatar Mar 14 '23 16:03 Hirse

It looks like it's not possible to add support for this for clients that are on TypeScript 4.4 yet. Our TypeScript minbar is 3.9, and adding a template literal type fails to compile on 3.9 (see the build failure on the Draft PR: #24646).

I'm going to mark this as Blocked for now. We can add support once:

To provide more context on those TS versions.

We will have a downleveling TS tool in place which will enable us to use latest versions and features of TS and ship valid types to users that are using older versions. This is not a silver bullet though and unfortunately this particular feature (Template string pattern index signature) cannot be down-leveled for older TS versions.

With all that set, blocker is clearly set - until our minbar is TS 4.4 we will not be able to support this.

There are workarounds (not ideal though): users can use type assertion to make the checker happy ( note that type assertion are dangerous )

Hotell avatar Mar 24 '23 16:03 Hotell

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

It is blocked but not resolved. Re-opening issue

YuanboXue-Amber avatar Nov 27 '23 11:11 YuanboXue-Amber