( ...types: (NodeTypes | PrimitiveTypes)[] )
| 243 | } |
| 244 | |
| 245 | export function assertNodeOrValueType<T extends t.Node>( |
| 246 | ...types: (NodeTypes | PrimitiveTypes)[] |
| 247 | ): Validator<T> { |
| 248 | function validate(node: T, key: string | { toString(): string }, val: any) { |
| 249 | const primitiveType = getType(val); |
| 250 | for (const type of types) { |
| 251 | if (primitiveType === type || is(type, val)) { |
| 252 | validateChild(node, key, val); |
| 253 | return; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | throw new TypeError( |
| 258 | `Property ${key} of ${ |
| 259 | node.type |
| 260 | } expected node to be of a type ${JSON.stringify( |
| 261 | types, |
| 262 | )} but instead got ${JSON.stringify(val?.type)}`, |
| 263 | ); |
| 264 | } |
| 265 | |
| 266 | validate.oneOfNodeOrValueTypes = types; |
| 267 | |
| 268 | return validate; |
| 269 | } |
| 270 | |
| 271 | export function assertValueType<T extends t.Node>( |
| 272 | type: PrimitiveTypes, |
no outgoing calls
no test coverage detected