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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects/_api Paths breaks with Array<T> or T[] in property types #166

Closed
zavierboyd opened this issue Dec 21, 2020 · 1 comment
Closed
Assignees
Labels
bug Something isn't working
Projects

Comments

@zavierboyd
Copy link

zavierboyd commented Dec 21, 2020

馃悶 Bug Report

Describe the bug

When using Object/_api Paths with an object that contains an Array the output type will union with List<string | number | symbol>

Reproduce the bug

import { } from 'ts-toolbelt'
import { Paths } from 'Object/_api'

// Using Array<T> notation
interface simpleObj1 { 'prop': Array<number>}
type out1 = Paths<simpleObj1>
// type out1 = List<string | number | symbol> | ["prop"?, number?]

// Using T[] notation
interface simpleObj2 { 'prop': number[]}
type out2 = Paths<simpleObj2>
// type out2 = List<string | number | symbol> | ["prop"?, number?]

// Inferring types using typeof
const value = { 'props': [1, 2, 3, 4, 5] }
type simpleObj3 = typeof value
// type simpleObj3 = {
//     props: number[];
// }
type out3 = PathsO<simpleObj3>
// type out3 = List<string | number | symbol> | ["props"?, number?]

Expected behavior

Expected the output type to be ['prop': number?] when using default Arrays without List<string | number | symbol>

// Expectation when inferring with typeof V or using T[] or Array<T> notation
interface simpleObj2 { 'prop': number[]}
type out2 = Paths<simpleObj2>
// type out2 = ["prop"?, number?]

Temporary Solution

// Using an interface array
interface numberArray {
    [key: number]: number
}
interface simpleObj4 { 'prop': numberArray}
type out4 = Paths<simpleObj3>
// type out4 = ['prop'?, number?]

Additional context

Versions:
"ts-toolbelt": "8.0.7"
"typescript": "4.1.3"

Tools:

  • Visual Studio Code: 1.52.1
@millsp millsp self-assigned this Dec 23, 2020
@millsp millsp added the bug Something isn't working label Dec 23, 2020
@millsp
Copy link
Owner

millsp commented Dec 23, 2020

Hey @zavierboyd, thanks for reporting this. I will look into it ASAP

@millsp millsp added this to To do in Board via automation Jan 29, 2021
@millsp millsp moved this from To do to Done in Board Jan 30, 2021
@millsp millsp closed this as completed in 3b62add Feb 1, 2021
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
Board
  
Done
Development

No branches or pull requests

2 participants