Last active
January 31, 2020 14:04
-
-
Save myuon/c583a4d94a0267fbf8b316028c9c3a35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type D<T> = { | |
[P in keyof T]?: T[P] extends Array<infer U> ? Array<D<U>> : T[P] | |
} | |
type W<V> = { | |
wrapper: V | |
} | |
type A = D<{ | |
hoge: number, | |
foo: W<{ bar: string }[]>, | |
}> | |
/* | |
Property 'wrapper' is missing in type 'never[]' but required in type 'W<{ bar: string; }[]>'.(2741) | |
input.ts(6, 5): 'wrapper' is declared here. | |
input.ts(11, 5): The expected type comes from property 'foo' which is declared here on type 'D<{ hoge: number; foo: W<{ bar: string; }[]>; }>' | |
*/ | |
const a: A = { | |
foo: [] | |
} |
Dつけたら動いた
type D<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ? Array<D<U>> : D<T[P]>
}
type W<V> = {
wrapper: V
}
type A = D<{
hoge: number,
foo: W<{ bar: string }[]>,
}>
const a: A = {
foo: {
wrapper: [{ bar: '' }, {}]
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こうすると
ここまでいけます。
それとPartialは配列は考慮しないのでの場合、{ bar: string }[]
が{bar: string}[]
のままなのは正しいです。であればAの型は以下のようになるので
bar
もoptionalになります。