millsp / ts-toolbelt

πŸ‘· TypeScript's largest type utility library

Home Page:https://millsp.github.io/ts-toolbelt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`F.AutoPath` doesn't work if `O` includes `string` values

nandorojo opened this issue Β· comments

🐞 Bug Report

Describe the bug

If you pass F.AutoPath<O, S> where O includes a string as one of its values, you get no autocomplete.

F.AutoPath<{ user: boolean }, S> // works
F.AutoPath<{ user: string }, S> // breaks

Reproduce the bug

See here.

import { F, O, S } from 'ts-toolbelt'

declare function get<Ob extends object, P extends string>(
  object: Ob,
  path: F.AutoPath<Ob, P>
): O.Path<Ob, S.Split<P, '.'>>

const works = get({ fast: true }, '')      // βœ… this errors

const breaks = get({ car: 'toyota' }, '') // 🚨 no error here, but it should

Expected behavior

Strings should work like any other field.

Possible Solution

Use F.AutoPath<O, S> | keyof O

Screenshots

Screen Shot 2021-11-30 at 4 50 31 PM

Screen Shot 2021-11-30 at 4 50 36 PM

Additional context

commented

Experience this as well!