Skip to content

Optional parameters with defined type not wrapping it with option variant. #4099

Closed
@kd4001

Description

@kd4001

I have 3 scenarios where a function take optional parameters.

let getModifiedTitle = (~title: someVariant=?) => {
    blah blah blah...
}
let getModifiedTitle = (~title=?) => {
    blah blah blah...
}
let getModifiedTitle = (~title: option(someVariant)=?) => {
    blah blah blah...
}

So in 1st scenario it doesn't wrap the title param with option where as in 2nd scenario it does. So to wrap it with option variant I have to explicitly wrap it.

Now the problem is none of the scenario gives error.
Where as 1st scenario should give an error.

For example,

Let's say I have below scenario.

type someVariant = 
    | Text(string)
    | Custom(unit => React.element);

let getModifiedTitle = (~title: someVariant=?) => {
    switch(title) {
       | Text(title) => <div>{React.string(title)}</div>
       | Custom(fn) => fn()
    }
}

Now if I call the function getModifiedTitle() and don't pass title, it won't throw error on compile time. Rather it would break in run time.

I think it should either wrap it with option variant and therefore it should ask to wrap it with option switch case or just raise an error on compile time.

The 2nd scenario handles this but the 1st scenario should throw an error.

For reproducing the issue
Please clone this repo - https://github.com/ka-ran/reason-react-boilerplate/tree/example
Checkout to example branch
Follow Readme.md .
Run the code.
Hope this helps

Desc- There are two components. Component1 and Component2. The code breaks in case of component2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions