-
-
Notifications
You must be signed in to change notification settings - Fork 313
Closed
Labels
awaiting upstreamreleasedThis issue/pull request has been released.This issue/pull request has been released.type:bugChanges fix a minor bugChanges fix a minor bug
Description
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.
Metadata
Metadata
Assignees
Labels
awaiting upstreamreleasedThis issue/pull request has been released.This issue/pull request has been released.type:bugChanges fix a minor bugChanges fix a minor bug