Skip to content

Ngx meta.withmanagerjsonpath

Home > @davidlj95/ngx-meta > withManagerJsonPath

withManagerJsonPath variable

Transforms a JSON Path specified as an array of keys into a string joined by dots.

Useful to use with provideNgxMetaManager() to avoid repeating same keys around.

Signature:

withManagerJsonPath: WithManagerJsonPath

Remarks

You can specify a type to ensure the keys are valid. See example below.

Beware that specifying a type won't work if:

The type refers other types and more than 2 levels are specified:

interface CustomMetadata { custom: Custom }
interface Custom { moar: Moar }

// 👇❌ Reports incorrect Typescript error about `never` type
withManagerJsonPath<CustomMetadata>('custom', 'moar', 'foo')
More than 3 keys are specified:

interface CustomMetadata {
  custom: {
    moar: {
      moarThanMoar: {
        foo: string
      }
    }
  }
}

// 👇❌ Reports incorrect Typescript error about `never` type
withManagerJsonPath<CustomMetadata>('custom', 'moar', 'moarThanMoar', 'foo') //
Omit the type to skip type checking and its limitations:

withManagerJsonPath('whatever', 'untyped', 'keys')

Example

interface CustomMetadata {
  custom: {
    title: string
  }
}

withManagerJsonPath<CustomMetadata>('custom','title') // ✅ No error. IDE helps you auto-complete.
withManagerJsonPath<CustomMetadata>('custom','not-a-prop') // ❌ Typescript error
withManagerJsonPath('no', 'type', 'checks')