Skip to content

Instantly share code, notes, and snippets.

@raould
Created January 5, 2020 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raould/f523e235751f26a83c72154dde298bc6 to your computer and use it in GitHub Desktop.
Save raould/f523e235751f26a83c72154dde298bc6 to your computer and use it in GitHub Desktop.
// see https://repl.it/repls/TemporalFrigidScientificcomputing
type DataPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];
type DataPropertiesOnly<T> = {
[P in DataPropertyNames<T>]?: T[P] extends object ? DTO<T[P]> : T[P]
};
export type DTO<T> = DataPropertiesOnly<T>;
interface X {
duration_msec: number;
available(now: number): boolean;
}
let x:DTO<X> = {
// this should be an error
// because it is missing
// duration_msec.
};
let y:X = {
...x
}
console.log("x", x);
console.log("y", y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment