Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example: AjScript must know which type is returned #44

Open
coolaj86 opened this issue Mar 22, 2023 · 1 comment
Open

Example: AjScript must know which type is returned #44

coolaj86 opened this issue Mar 22, 2023 · 1 comment

Comments

@coolaj86
Copy link
Collaborator

coolaj86 commented Mar 22, 2023

See dashhive/DashHD.js#26.

var hdpath = `m/44'/5'/0'/0`;
var xKey = DashHd.derivePath(walletKey, hdpath)

Depending on the string value, xKey could be of the generic type HDKey, but it could be of a more specific type - such as HDWalletKey, HDAccountKey, HDXKey, or HDAddressKey.

The logic for returning the types is not yet implemented, but it could be.

None of the branching logic will depend on anything but how the string is split and operated on, so it's possible to analyze at dev time.

@coolaj86
Copy link
Collaborator Author

Another example:

    let resp = await fetch(url, opts);
    /** @type {Record<String,String|Array<String>>} */
    let headers = {};
    for (let [key, value] of resp.headers.entries()) {
      if (headers[key]) {
        let isArray = Array.isArray(headers[key]);
        if (!isArray) {
          //@ts-ignore
          headers[key] = [headers[key]];
        }
        //@ts-ignore
        headers[key].push(value);
      }
    }

It should know that it's an array in the one case and not in the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant