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

WIP: feat: add better handing for typescript complier #2088

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

Jordan-Hall
Copy link

@Jordan-Hall Jordan-Hall commented Jun 10, 2022

fix: soft file there is no props defined

Check if export is either a class or function that returns JSX element
This allows for none exported JSX functions in the file.

For example if you had the following file:

import React from "react";
import DropdownArrowDown from '../dropdownArrowDown';
import { AutoCompleteOptions, AutoCompleteValue, RealAutoCompleteOptions } from "./types";


export interface AutoCompleteTypes {
    id: string;
    autoselect: boolean;
}

export const autoCompleteDefaultProps: Partial<AutoCompleteTypes> = {
    autoselect: false,
};


export const AutoComplete = (props:AutoCompleteTypes) => {...}

The export default would crash and file due to not having props. Now it will check its a function or a class before trying to convert to dash py

fix: soft file there is no props defined

Check if export is either a class or  function that returns JSX element
This allows for none exported JSX functions in the file.

Signed-off-by: Jordan Hall <jordan@libertyware.co.uk>
@Jordan-Hall
Copy link
Author

@T4rk1n before i carry on and add Unit test for these. This is what I was thinking to solve #2066 (comment). The error comes from not checking the type is related to JSX before trying to work out the props.

export const defaultProps = {
   address: "abc...."
}

would cause the complier to break. So while i was at it, i thought its best to check the return type is an element. If this is ok, I'll take a look at how to add support for multiple components in a single file. Currently you always override the docs each time which isn't ideal

dash/extract-meta.js Outdated Show resolved Hide resolved
@Jordan-Hall
Copy link
Author

The failed unit test relates to JSX just returning null. In real world I can't ever expect it not to be Element. But happy to remove that extra check for JSX

@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 10, 2022

@T4rk1n before i carry on and add Unit test for these. This is what I was thinking to solve #2066 (comment). The error comes from not checking the type is related to JSX before trying to work out the props.

export const defaultProps = {
   address: "abc...."
}

would cause the complier to break. So while i was at it, i thought its best to check the return type is an element. If this is ok, I'll take a look at how to add support for multiple components in a single file. Currently you always override the docs each time which isn't ideal

The failed unit test relates to JSX just returning null. In real world I can't ever expect it not to be Element. But happy to remove that extra check for JSX

Seems ok, just make sure that null is also a valid return type, some components don't need to render anything (eg: dcc.Store) and thus return null.

@Jordan-Hall Jordan-Hall marked this pull request as ready for review June 10, 2022 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants