Skip to content

Commit

Permalink
Fix broken object and lazy types
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Dec 28, 2023
1 parent b353c60 commit 6c33831
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lib/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Returns all the keys from T where `undefined` can be assigned to.
*/
type OptionalKeys<T> = {
[K in keyof T]-?: K extends any ? (undefined extends T[K] ? K : never) : never;
[K in keyof T]-?: undefined extends T[K] ? K : never;
}[keyof T];

type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
Expand All @@ -25,7 +25,7 @@ type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
*
* {
* name: string;
* age?: number | null;
* age?: number | null | undefined;
* ^
* Note the question mark
* }
Expand Down
11 changes: 6 additions & 5 deletions src/lib/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { define } from '../Decoder';
import { subtract, isPojo } from '../_utils';
import type { Annotation } from '../annotate';
import type { Decoder, DecodeResult } from '../Decoder';
import type { AllowImplicit } from './_helpers';

// TODO: Restore AllowImplicit here somehow
// import type { AllowImplicit } from './_helpers';
type ObjectDecoderType<T> = {
type ObjectDecoderType<T> = AllowImplicit<{
[K in keyof T]: T[K] extends Decoder<infer V> ? V : never;
};
}>;

/**
* Accepts any "plain old JavaScript object", but doesn't validate its keys or
Expand Down Expand Up @@ -170,7 +169,9 @@ export function inexact<O extends Record<string, Decoder<any>>>(
} & Record<string, unknown>;
allkeys.forEach((k) => {
if (safekeys.has(k)) {
const value = safepart[k];
const value =
// @ts-expect-error - look into this later
safepart[k];
if (value !== undefined) {
// @ts-expect-error - look into this later
rv[k] = value;
Expand Down

0 comments on commit 6c33831

Please sign in to comment.