Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Typing incomplete on Templates (TypeScript, React) #1689

Closed
ghost opened this issue May 19, 2022 · 8 comments · Fixed by #1981
Closed

[BUG] Typing incomplete on Templates (TypeScript, React) #1689

ghost opened this issue May 19, 2022 · 8 comments · Fixed by #1981
Assignees
Labels
bug Something isn't working State: Completed
Milestone

Comments

@ghost
Copy link

ghost commented May 19, 2022

Describe the bug
Even though the documentation example utilizes a typescript project, it does not seem that this library is typescript compatible. Through a few test cases, the typing on objects is incomplete or incorrect.

To Reproduce
Steps to reproduce the behavior:

Example 1:

Say you want to utilize a selected person that someone chooses through people picker

<PeoplePicker selectionChanged={(selection) => console.log(selection.detail)} />

Typescript will complain that TS2339: Property 'detail' does not exist on type 'Event'..

Example 2:

Try to use a template as described in the documentation (which is in a "tsx" format there)

import { MgtTemplateProps } from '@microsoft/mgt-react';

const MyEvent = (props: MgtTemplateProps) => {
  const { event } = props.dataContext;
  return <div>
    {event.subject}<br />
    {event.attendees
      .map((attendee: any) => attendee.emailAddress.name)
      .join(', ')}
  </div>;
};

You will receive errors such as "ESLint: Unsafe assignment of an any value. (@typescript-eslint/no-unsafe-assignment)"

Expected behavior
If examples utilize Typescript then you would expect that the library actually supports Typescript.

@ghost ghost added bug Something isn't working Needs: Triage 🔍 labels May 19, 2022
@ghost
Copy link

ghost commented May 19, 2022

Hello luffespresso, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@sebastienlevert
Copy link
Contributor

We support TypeScript (and we are in fact building in TypeScript). Which version of TypeScript are you targeting?

@ghost
Copy link
Author

ghost commented May 19, 2022

We support TypeScript (and we are in fact building in TypeScript). Which version of TypeScript are you targeting?

I am using 4.4.4 locally. Can you verify the examples I linked above do in fact work? I can troubleshoot on my end if it is a local issue, just want to ensure that the support is in fact there properly.

@sebastienlevert
Copy link
Contributor

We'll validate the sample within the repo. They might be a bit outdated.

Can you test if this works for you : https://github.com/sebastienlevert/mgt-sandbox/tree/main/10-mgt-react

@ghost
Copy link
Author

ghost commented May 19, 2022

We'll validate the sample within the repo. They might be a bit outdated.

Can you test if this works for you : https://github.com/sebastienlevert/mgt-sandbox/tree/main/10-mgt-react

Your example "works" as in it runs, but even looking at this line:
https://github.com/sebastienlevert/mgt-sandbox/blob/main/10-mgt-react/src/App.tsx#L59

the dataContext property has "any" type, so below that when you use sub properties of email, any TS linter would present you with errors such as "ESLint: Unsafe assignment of an any value".

The typing of the dataContext props is not present (at least not in the examples) so how does the user/IDE know what to expect when accessing properties of email in that case, such as email.sender.emailAddress.address?

@ghost ghost changed the title [BUG] Not Typescript compatible [BUG] Typing incomplete on Templates (TypeScript, React) May 24, 2022
@njaci1 njaci1 self-assigned this Sep 12, 2022
@gavinbarron
Copy link
Member

This is an interesting issue.

We generate the typing of events and properties on the React components based on the results that we get from the web components analyzer

I have an open issue on that repo asking for information on why we are not getting the types of the event to match the CustomEvent type that we are actually using and documenting. runem/web-component-analyzer#248

@gavinbarron
Copy link
Member

While looking at another matter I found @custom-elements-manifest/analyzer this might be what we need to close this issue

@gavinbarron gavinbarron mentioned this issue Dec 9, 2022
6 tasks
@ghost ghost added the State: In Review label Dec 9, 2022
@gavinbarron gavinbarron added this to the v3.0.0 milestone Mar 9, 2023
@gavinbarron
Copy link
Member

@luffespresso I'm marking this closed this work has been done and is available as part of our v3.0.0-preview.1 release.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working State: Completed
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants