Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active September 17, 2018 11:21
Show Gist options
  • Select an option

  • Save dewey92/14a14c8795f341c2ee70d3792caca34c to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/14a14c8795f341c2ee70d3792caca34c to your computer and use it in GitHub Desktop.
Phantom Type Validation
class FormData<T> {
private readonly __data__: T;
constructor(value: any) { }
}
interface Unvalidated { __unval__: never }
interface Validated { __val__: never }
declare function validate(data: FormData<Unvalidated>): FormData<Validated>;
declare function sendToBackend(payload: FormData<Validated>): Promise<any>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment