-
Notifications
You must be signed in to change notification settings - Fork 1
/
8.ts
46 lines (36 loc) · 1.11 KB
/
8.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// reference from Oliver's share: https://gist.github.com/OliverUv/ce74cb9fb6ee3a5d64ac77cb6c4bd874
export interface WithDate {
date_added_unix_s:number;
}
export interface WithMetadata {
type:string;
author:string; // user id
version:number; // If the data format changes, bump this number
dependencies:string[];
}
export interface WithContentHash {
reference:string;
}
export interface WithContentBuffer {
buffer:Uint8Array;
}
export interface WithName {
name:string;
}
export type AddContent = WithMetadata & WithName & WithContentBuffer;
export type Content = WithMetadata & WithContentBuffer & WithDate;
export type ContentReference = WithMetadata & WithDate & WithContentHash;
// This can be a handy way, a bit less compliacted than using the
// Diff and Filter generic types
// -------------------------------------
// here is how to implement `Partial2`
import { Omit } from './5';
type Partial2<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
interface I {
a:string;
b:number;
c:'a' | 'b' | 'c';
d:(a:number) => string;
}
type PI = Partial2<I, 'a' | 'c'>;
const pi = null as PI;