Skip to content

(obj)

object literals and object-like patterns

clojure
(obj props?)

Where:

  1. props: properties within the object *

Matching:

  1. object literals, e.g. {}
  2. object types (TypeScript), e.g. { a: 1 }
  3. destructuring patterns, e.g. { a, b } = x
  4. function parameters, e.g. function x({ a })

Behavior

  • Matches object literals, TypeScript object type annotations, and destructuring patterns.
  • TypeScript object types are matched, but filtering by their children (call signatures, construct signatures, index signatures, method signatures) is not yet supported. Only property signatures can be filtered using (prop).

Examples

Find API response objects that lack error handling fields.

clojure
(obj (:and (prop data) (:not (prop error))))

Selects in lines { 1, 3 } but not in { 2 }:

typescript
const response = { data: users }
const safeResponse = { data: users, error: null }
const partial = { data: {} }

Locate configuration objects with specific required fields before migration.

clojure
(obj (:and (prop host) (prop port) (:not (prop timeout))))

Selects in lines { 1 } but not in { 2, 3 }:

typescript
const config = { host: 'localhost', port: 3000 }
const fullConfig = { host: 'localhost', port: 3000, timeout: 5000 }
const partial = { host: 'localhost' }

Find functions accepting destructured parameters to refactor their signatures.

clojure
(fun _ (arg _ (obj (prop config))))

Selects in lines { 1, 2 } but not in { 3 }:

typescript
function setup({ config }) {}
function init({ config, options }) {}
function run(config) {}

Arguments

props

Copyright © 2022-present Semantic Works, Inc.