Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Support for complicated, nonstandard properties #42

Open
fwielstra opened this issue Jun 18, 2019 · 0 comments
Open

Support for complicated, nonstandard properties #42

fwielstra opened this issue Jun 18, 2019 · 0 comments

Comments

@fwielstra
Copy link

fwielstra commented Jun 18, 2019

Is there a way to replace _.get() with ts-optchain for the following use case?

const response = {
  headers: {
    "Content-Type": "application/json"
  }
};

const contentType = _.get(response, "headers.Content-Type");

That is, while the dash is not allowed in a function name / function call likeoc(response).headers.Content-Type(), it is still a valid object key.

Maybe a check on the argument? That is, if it matches a property in the object return that, else consider it the default argument. Examples:

 // expected "application/json"
const contentType = oc(response).headers("Content-Type");

// expected 0 as default value because content-length property does not exist.
const contentLength = oc(response).headers("Content-Length", 0);

// expected empty object / default value because argument does not match one of headers' properties.
const headers = oc(response).headers({})
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant