Description
After omitting some fields from existing Schema types, the types of remained fields become unknown.
Steps to reproduce
const api = new Gitlab({ token: 'token' });
const branch = await api.Branches.show('projectId', 'master');
const commitDiff = await api.Commits.diff('projectId', branch.commit.id);
// TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string'.
Expected behaviour
The type of branch.commit.id should be string.
Actual behaviour
The type of branch.commit.id is unknown.
Possible fixes
All Schema types extend from Record<string, unknown>. For example:
interface Foo extends Record<string, unknown> {
x: string;
y: number;
z: boolean;
}
type K0 = keyof Foo; // string | number
type K1 = Exclude<K0, 'x'>; // string | number
type T = Omit<Foo, 'x'>; // { [x: string]: unknown, [x: number]: unknown }
While the other is not extended from Record type:
interface Bar {
x: string;
y: number;
z: boolean;
}
type K0 = keyof Bar; // 'x' | 'y' | 'z'
type K1 = Exclude<K0, 'x'>; // 'y' | 'z'
type T = Omit<Bar, 'x'>; // { y: number, z: boolean }
Because Omit is implemented by Exclude, so the excluded keys is incorrect if the object type extends from Record type.
Description
After omitting some fields from existing Schema types, the types of remained fields become
unknown.Steps to reproduce
Expected behaviour
The type of
branch.commit.idshould bestring.Actual behaviour
The type of
branch.commit.idisunknown.Possible fixes
All Schema types extend from
Record<string, unknown>. For example:While the other is not extended from
Recordtype:Because
Omitis implemented byExclude, so the excluded keys is incorrect if the object type extends fromRecordtype.