samhh / fp-ts-std

The missing pseudo-standard library for fp-ts.
https://samhh.github.io/fp-ts-std/
MIT License
207 stars 27 forks source link

fix: add better struct pick type #163

Closed thomasvargiu closed 1 year ago

thomasvargiu commented 1 year ago

Add better Pick type to Struct and ReadonlyStruct modules.

Example:

import { pick } from 'fp-ts-std/Struct'

const AttributesKeys = ['key1' as const, 'key2' as const]
const getAttributes = <A extends Record<string, unknown>>(x: A) =>
    pipe(x, pick(AttributesKeys))

declare const y: { key1: string, foo: string }

const result = getAttributes(y) 

Currently:

typeof result = {
    key1: string
    key2: unknown
}

With this MR:

typeof result = {
    key1: string
}
thomasvargiu commented 1 year ago

Honestly I'm not sure. It could be too much strict as a type

thomasvargiu commented 1 year ago

Definitely it will cause other problems