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

Fix Union type with DeepMap? #169

Closed
rnnyrk opened this issue Dec 14, 2020 · 1 comment
Closed

Fix Union type with DeepMap? #169

rnnyrk opened this issue Dec 14, 2020 · 1 comment

Comments

@rnnyrk
Copy link

rnnyrk commented Dec 14, 2020

Hi there,

I'm nt sure if I do understand your examples correctly. But I have the following types:

export type StartEndType = {
  start_date: string;
  end_date: string;
};

export type PayrollContract = StartEndType & {
  type: 'ON_PAYROLL';
  yearly_holidays: number;
};

export type FreelanceContract = StartEndType & {
  type: 'FREELANCE';
  hourly_rate: number;
};

export type Contract = PayrollContract | FreelanceContract;

Is it possible to fix this DeepMap issue which isn't supported by TypeScript out of the box?

Property 'yearly_holidays' does not exist on type 'DeepMap<PayrollContract, FieldError> | DeepMap<FreelanceContract, FieldError>'.
  Property 'yearly_holidays' does not exist on type 'DeepMap<FreelanceContract, FieldError>'.

I was looking at ValueOf or LiteralUnion, but not sure if I do understand it correctly.

In my component it looks like:

{contractType === 'ON_PAYROLL' ? (
  <Number name="yearly_holidays"  />
) : contractType === 'FREELANCE' && (
  <Number name="hourly_rate" />
)}

When I hover contract, it knows that it's one of ON_PAYROLL or FREELANCE.

Thanks in advance.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

We don't have a DeepMap type. Are you sure you opened this issue in the correct repo?

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

No branches or pull requests

2 participants