When T
has no keys that are known at compile time, the Result of Paths<T>
is not assignable to the second argument of Get
.
import type { Get, Paths } from 'type-fest'
interface Bug<T extends {}> {
props: Get<T, Paths<T>>
}
produces the error
Type 'Paths<T>' does not satisfy the constraint 'readonly string[] | LiteralStringUnion<ToString<_Paths<T, { maxRecursionDepth: 10; bracketNotation: false; }> | _Paths<T, { maxRecursionDepth: 10; bracketNotation: true; }>>>'.
Type 'number | `${number}`' is not assignable to type 'readonly string[] | LiteralStringUnion<ToString<_Paths<T, { maxRecursionDepth: 10; bracketNotation: false; }> | _Paths<T, { maxRecursionDepth: 10; bracketNotation: true; }>>>'.
Type 'number' is not assignable to type 'readonly string[] | LiteralStringUnion<ToString<_Paths<T, { maxRecursionDepth: 10; bracketNotation: false; }> | _Paths<T, { maxRecursionDepth: 10; bracketNotation: true; }>>>'.
I expect the code not to produce a compilation error. Specifically, Paths<T>
should be a valid argument to Get<T, ⋅>
for all T
that are neither null
nor undefined
. (If I’m not mistaken, every other type in javascript does have properties).
In instances where T
has a concrete type, the Bug::props
type should be inferred.
interface Foo {
key: number
}
let bar!: Bug<Foo>
let props = bar.props // number
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too