Skip to content

Instantly share code, notes, and snippets.

@Evanion
Evanion / exclude-null.ts
Created April 25, 2024 09:51
Excludes `null`, in an object, and replaces it with `undefined` in a way that TypeScript understands it.
type ExcludeNull<T> = {
[K in keyof T]-?: null extends T[K] ? Exclude<T[K], null> : T[K];
};
/**
* Filters out any `null` values and makes them `undefined`.
* It also filters out the type of the object so the TS parser understands it.
* @param obj Object containing null types
* @returns
*/
@Evanion
Evanion / input.decorator.ts
Created November 19, 2024 08:05
Input decorator
import 'reflect-metadata';
import { InputHTMLAttributes } from 'react';
import { ClassConstructor } from 'class-transformer';
export type InputOptions = Omit<
InputHTMLAttributes<HTMLInputElement>,
'name'
> & {
label?: string;
};