Skip to content

Commit

Permalink
chore: Satisfy updated Typescript (4.8.2) & Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Aug 27, 2022
1 parent c3c265b commit 26526d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/doc/createNode.ts
Expand Up @@ -48,7 +48,7 @@ export function createNode(
value instanceof String ||
value instanceof Number ||
value instanceof Boolean ||
(typeof BigInt === 'function' && value instanceof BigInt) // not supported everywhere
(typeof BigInt !== 'undefined' && value instanceof BigInt) // not supported everywhere
) {
// https://tc39.es/ecma262/#sec-serializejsonproperty
value = value.valueOf()
Expand Down
7 changes: 6 additions & 1 deletion src/nodes/YAMLMap.ts
Expand Up @@ -9,6 +9,11 @@ import { Pair } from './Pair.js'
import { isScalarValue, Scalar } from './Scalar.js'
import type { ToJSContext } from './toJS.js'

export type MapLike =
| Map<unknown, unknown>
| Set<unknown>
| Record<string | number | symbol, unknown>

export function findPair<K = unknown, V = unknown>(
items: Iterable<Pair<K, V>>,
key: unknown
Expand Down Expand Up @@ -105,7 +110,7 @@ export class YAMLMap<K = unknown, V = unknown> extends Collection {
* @param {Class} Type - If set, forces the returned collection type
* @returns Instance of Type, Map, or Object
*/
toJSON<T = unknown>(
toJSON<T extends MapLike = Map<unknown, unknown>>(
_?: unknown,
ctx?: ToJSContext,
Type?: { new (): T }
Expand Down
10 changes: 2 additions & 8 deletions src/nodes/YAMLSeq.ts
Expand Up @@ -58,14 +58,8 @@ export class YAMLSeq<T = unknown> extends Collection {
*/
get(key: unknown, keepScalar: true): Scalar<T> | undefined
get(key: unknown, keepScalar?: false): T | undefined
get(
key: unknown,
keepScalar?: boolean
): T | Scalar<T> | undefined
get(
key: unknown,
keepScalar?: boolean
): T | Scalar<T> | undefined {
get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined
get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined {
const idx = asItemIndex(key)
if (typeof idx !== 'number') return undefined
const it = this.items[idx]
Expand Down
11 changes: 3 additions & 8 deletions src/nodes/addPairToJSMap.ts
Expand Up @@ -4,15 +4,13 @@ import { isAlias, isMap, isNode, isScalar, isSeq } from './Node.js'
import type { Pair } from './Pair.js'
import { Scalar } from './Scalar.js'
import { toJS, ToJSContext } from './toJS.js'
import type { MapLike } from './YAMLMap.js'

const MERGE_KEY = '<<'

export function addPairToJSMap(
ctx: ToJSContext | undefined,
map:
| Map<unknown, unknown>
| Set<unknown>
| Record<string | number | symbol, unknown>,
map: MapLike,
{ key, value }: Pair
) {
if (ctx?.doc.schema.merge && isMergeKey(key)) {
Expand Down Expand Up @@ -58,10 +56,7 @@ const isMergeKey = (key: unknown) =>
// later mapping nodes. -- http://yaml.org/type/merge.html
function mergeToJSMap(
ctx: ToJSContext | undefined,
map:
| Map<unknown, unknown>
| Set<unknown>
| Record<string | number | symbol, unknown>,
map: MapLike,
value: unknown
) {
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value
Expand Down
1 change: 1 addition & 0 deletions src/schema/yaml-1.1/set.ts
Expand Up @@ -24,6 +24,7 @@ export class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null> {
let pair: Pair<T, Scalar<null> | null>
if (isPair(key)) pair = key
else if (
key &&
typeof key === 'object' &&
'key' in key &&
'value' in key &&
Expand Down

0 comments on commit 26526d7

Please sign in to comment.