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

O.PathValid unexpected behaviour with depth >= 3 #147

Closed
Dot-H opened this issue Sep 20, 2020 · 2 comments
Closed

O.PathValid unexpected behaviour with depth >= 3 #147

Dot-H opened this issue Sep 20, 2020 · 2 comments
Labels
works as intended It works this way

Comments

@Dot-H
Copy link

Dot-H commented Sep 20, 2020

🐞 Bug Report

Describe the bug

Hi 👋

When trying to access an object deeper than 3 indirection using O.PathValid, the path becomes invalid.

Reproduce the bug

import { O, A, L } from 'ts-toolbelt'

interface IManagement {
  // keep those fields for the error
  id: number
  enterprise_did_id: number
  label: string
  code: string

  service?: IService[]
}

interface IService {
  // ...some fields
  role?: IRole[]
}

interface IRole {
  // ...some fields
  id: number
}

interface EDID {
  // ...some fields
  management?: IManagement[]
}

function updateEnterpriseDidElement<P extends L.List<string>>(
    ...path: A.Cast<P, O.PathValid<EDID, P>>
): void { }


// error TS2345: Argument of type '"role"' is not assignable to parameter of
// type '"service" | "id" | "enterprise_did_id" | "label" | "code"'.
updateEnterpriseDidElement("management", "service", "role")

Expected behavior

The arguments passed to the updateEnterpriseDidElement should be valid. Am I missing something ?

@millsp
Copy link
Owner

millsp commented Sep 21, 2020

Hey @Dot-H, you made a little mistake. You must allow numbers because IManagement is an array.

function updateEnterpriseDidElement<P extends List<string | number>>(
    ...path: Cast<P, PathValid<EDID, P>>
): void { }

updateEnterpriseDidElement('management', 0, 'service', 'role')

@millsp millsp closed this as completed Sep 21, 2020
@millsp millsp added the works as intended It works this way label Sep 21, 2020
@Dot-H
Copy link
Author

Dot-H commented Sep 22, 2020

Ups, sorry for the false alarm and thanks for the help 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
works as intended It works this way
Projects
None yet
Development

No branches or pull requests

2 participants