Skip to content

chore/typescript improvements#347

Merged
Mortaro merged 2 commits intonullstack:nextfrom
mayconfsousa:chore/typescript-improvements
May 22, 2023
Merged

chore/typescript improvements#347
Mortaro merged 2 commits intonullstack:nextfrom
mayconfsousa:chore/typescript-improvements

Conversation

@mayconfsousa
Copy link
Copy Markdown
Contributor

@mayconfsousa mayconfsousa commented May 20, 2023

  1. The children property is always an array inside the component.
    The children property type should be NullstackFragment instead of NullstackNode.
class Button extends Nullstack {

  render({ children }: NullstackClientContext) {
    const hasChildren = children.filter(Boolean).length > 0 // <-- children is always an array at this point

    return <button>{hasChildren ? children : 'Default Text'}</button>
  }

}
  1. The current Typescript types don't support adding children as a required property.
interface ButtonWithChildrenProps {
  children: JSX.Element // <-- this component must have children
}

class ButtonWithChildren extends Nullstack<ButtonWithChildrenProps> {

  render({ children }: NullstackClientContext) {
    return <button>{children}</button>
  }

}
<ButtonWithChildren>ButtonWithChildren</ButtonWithChildren> // <-- ERROR here...
  1. The way of passing values to the class and style properties mentioned below will fail in strict mode.
    It should allow falsy values or strings instead.
class ComponentWithStyles extends Nullstack {

  testVariable = false

  render() {
    return [
      <button class={this.testVariable && 'class-a'}>Button A</button>,
      <button class={[this.testVariable && 'class-a']}>Button B</button>,
      <button style={this.testVariable && 'style-a'}>Button C</button>,
      <button style={[this.testVariable && 'style-a']}>Button D</button>,
    ]
  }

}
  1. Upgrade the eslint-plugin-nullstack version

@mayconfsousa mayconfsousa changed the title Chore/typescript improvements chore/typescript improvements May 20, 2023
@GuiDevloper
Copy link
Copy Markdown
Member

@brunolm

@Mortaro Mortaro merged commit c7c792a into nullstack:next May 22, 2023
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.

3 participants