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

Error "The value defined for prop 'value' must be of type 'Date'" #112

Open
efoken opened this issue Sep 22, 2023 · 2 comments
Open

Error "The value defined for prop 'value' must be of type 'Date'" #112

efoken opened this issue Sep 22, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@efoken
Copy link
Contributor

efoken commented Sep 22, 2023

Describe the bug
I'm getting error The value defined for prop 'value' must be of type 'Date' when passing a string to a prop of type Date. Shouldn't it be parsed the Date object when a string is given since 1.73.0?

I tried this within Storybook.

Here's my simplified DatePicker component:

function datePicker() {
  const [value, setValue] = useProp<Date>('value');
  return <host shadowDom />;
}

datePicker.props = {
  value: Date,
};

Browser (please complete the following information):

  • Chrome 116

To Reproduce
Steps to reproduce the behavior:

  1. Create a component using a value prop of type Date
  2. Pass a string to value in HTML like <my-date-picker value="2023-09-22">
  3. See error in console

Expected behavior
String value should be parsed to a Date.

@efoken efoken added the bug Something isn't working label Sep 22, 2023
@efoken
Copy link
Contributor Author

efoken commented Sep 22, 2023

Just used this as a workaround for now, seems to work:

datePicker.props = {
  value: createType((value) => (value instanceof Date ? value : new Date(value))),
}

@UpperCod
Copy link
Member

Hi @efoken , sorry for not responding earlier. Atomico has improved the types by allowing transformations by instance if it is not covered by Atomico, but this only covers inputs as attributes.

To force Atomico to allow input via attributes, you can use the "$" prefix, for example:

<my-component $date="2023-03-11"/>

... Now I think it would be useful in the future to add logic that allows working together with props that have both string and non-string inputs. For example, if the type is declared as Number and it receives "0", the output would be 0. What do you think about what was mentioned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants