Skip to content

Struct of These #1648

Answered by ammut
florianbepunkt asked this question in Q&A
Jan 4, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

There's two issues here, from what I can tell. First, in TH.map((s) => ...), s is { a1: number; a2: never; a3: string }, including the irksome a2: never. You could use a helper type like this:

type FilterNeverKeys<K extends keyof S, S> = K extends unknown ? S[K] extends never ?  never : K : never;
type FilterNeverS<S> = { [K in FilterNeverKeys<keyof S, S>]: S[K] };

// use like this
const filterNever = <S extends Record<string, unknown>>(s: S): FilterNeverS<S> => s;
pipe(
  someStruct,
  sequenceS(TH.getApply(SG.last())),
  TH.map(filterNever),
  TH.map((s) => s.a2), // Error: property 'a2' does not exist on type
);

to filter out the props with type never, but do you actually need this? …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@florianbepunkt
Comment options

Answer selected by florianbepunkt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants