Created
January 5, 2020 15:18
-
-
Save raould/f523e235751f26a83c72154dde298bc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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