Recently, I attempted the following code snippet:
import R from 'ramda'
import fs from 'fs'
import path from 'path'
import {promisify} from 'util'
const readFile = promisify(fs.readFile)
export async function discoverPackageInfo(): Promise<{
name: string,
version: string
description: string
}> {
return readFile(path.join(__dirname, '..', 'package.json'))
.then(b => b.toString())
.then(JSON.parse)
.then(R.pick([
'name',
'description',
'version',
]))
}
However, the outcome was not as expected. An error was thrown:
src/file.ts:13:3 - error TS2322: Type '{ name: string; version: string; description: string; } | Pick<any, never>' is not assignable to type '{ name: string; version: string; description: string; }'.
Type 'Pick<any, never>' is missing the following properties from type '{ name: string; version: string; description: string; }': name, version, description
13 return readFile(path.join(__dirname, '..', 'package.json'))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 .then(b => b.toString())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
19 'version',
~~~~~~~~~~~~~~~~
20 ]))
~~~~~~~
I'm unsure of what mistake I made here. Can someone help identify it?