dash icon indicating copy to clipboard operation
dash copied to clipboard

add better handing for typescript compiler

Open Jordan-Hall opened this issue 3 years ago • 5 comments

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

Jordan-Hall avatar Jun 10 '22 07:06 Jordan-Hall

@T4rk1n before i carry on and add Unit test for these. This is what I was thinking to solve https://github.com/plotly/dash/issues/2066#issuecomment-1150916950. 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

Jordan-Hall avatar Jun 10 '22 07:06 Jordan-Hall

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

Jordan-Hall avatar Jun 10 '22 08:06 Jordan-Hall

@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.

T4rk1n avatar Jun 10 '22 13:06 T4rk1n