Typed Get hard #utils #template-literal

by Anthony Fu @antfu

Take the Challenge    日本語

The [`get` function in lodash](https://lodash.com/docs/4.17.15#get) is a quite convenient helper for accessing nested values in JavaScript. However, when we come to TypeScript, using functions like this will make you lose the type information. With TS 4.1's upcoming [Template Literal Types](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types) feature, properly typing `get` becomes possible. Can you implement it? For example, ```ts type Data = { foo: { bar: { value: 'foobar', count: 6, }, included: true, }, hello: 'world' } type A = Get // 'world' type B = Get // 6 type C = Get // { value: 'foobar', count: 6 } ``` Accessing arrays is not required in this challenge.
Back Share your Solutions Check out Solutions