Skip to content

Commit

Permalink
Marker.isMarkerObject
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Mar 8, 2023
1 parent 62c8992 commit aaab9ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/markers/src/common/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ export interface Marker<T> {
data: T;
}
export namespace Marker {
export function is(value: unknown): value is Marker<object>;
export function is<T>(value: unknown, subTypeCheck: (value: unknown) => value is T): value is Marker<T>;
export function is(value: unknown, subTypeCheck?: (value: unknown) => boolean): boolean {
subTypeCheck ??= isObject;

export function is<T>(value: unknown, subTypeCheck: (value: unknown) => value is T): value is Marker<T> {
return isObject<Marker<object>>(value)
&& !Array.isArray(value)
&& subTypeCheck(value.data)
&& isString(value.uri)
&& isString(value.owner);
}

export function isMarkerObject(value: unknown): value is Marker<object> {
return is(value, isObject);
}
}
2 changes: 1 addition & 1 deletion packages/markers/src/common/problem-marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export interface ProblemMarker extends Marker<Diagnostic> {

export namespace ProblemMarker {
export function is(node: unknown): node is ProblemMarker {
return Marker.is(node) && node.kind === PROBLEM_KIND;
return Marker.isMarkerObject(node) && node.kind === PROBLEM_KIND;
}
}

0 comments on commit aaab9ce

Please sign in to comment.