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

Support Optional Typed Children #582

Merged
merged 6 commits into from
Nov 8, 2019

Conversation

agubler
Copy link
Member

@agubler agubler commented Nov 8, 2019

Type: bug

The following has been addressed in the PR:

Description:

Add support for using undefined as a union type to indicate that children are optional for the end user, and as such will possibly be undefined in the widget.

import { create } from '@dojo/framework/core/vdom';

type MyWidgetChildren = undefined | (() => string);

const factory = create().children<MyWidgetChildren>();

const MyWidget = factory(function MyWidget({ children }) {
    const [c] = children();
    if (c) {
        return c();
    }
    return null;
});

<MyWidget>{() => 'Hello Dojo'}</MyWidget>;
<MyWidget />;
w(MyWidget, {}, [() => 'Hello Dojo']);
w(MyWidget, {});
MyWidget({}, [() => 'Hello Dojo']);
MyWidget({});

Resolves issues with using w and calling functional widgets directly where the expected type was not being converted to an array but children is always expected to be an array.

Resolves #581

@agubler agubler merged commit 5728f2e into dojo:master Nov 8, 2019
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.

Type errors when using optional typed children
2 participants