Skip to content

Instantly share code, notes, and snippets.

@kasper573
Created September 8, 2018 17:41
Show Gist options
  • Save kasper573/c02aff5c67feb39fc74476eaec3de74b to your computer and use it in GitHub Desktop.
Save kasper573/c02aff5c67feb39fc74476eaec3de74b to your computer and use it in GitHub Desktop.
type QueryValue = number | string | boolean | Date;
type Query<T> = {
[P in SubTypeKeys<T, QueryValue>]?: T[P] | T[P][]
};
type SubTypeKeys<Base, Condition> = {
[Key in keyof Base]: Base[Key] extends Condition ? Key : never
}[keyof Base];
class Foo {
bar: string;
}
type Combination = number & {whatever: string};
const value: Combination = null;
const query: Query<Foo> = value; // Should not be allowed
@lumie1337
Copy link

type Example = {
    [P in ("a" | "b")]?: string
}

let opaqueType: number & { whatever: string };
let example: Example = opaqueType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment