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

Add LiteralType as array accessor #1900

Open
NikitaFedorov1 opened this issue Mar 28, 2024 · 0 comments
Open

Add LiteralType as array accessor #1900

NikitaFedorov1 opened this issue Mar 28, 2024 · 0 comments

Comments

@NikitaFedorov1
Copy link

if (type instanceof ArrayType && index instanceof NumberType) {

Should allow literal for item[][0] => { 0: item }:

if (type instanceof ArrayType && (index instanceof NumberType || index instanceof LiteralType)) {
        return type.getItem();
}

For type:

type GetDepositProcessedResult = {
    trx: {
        _items: {
            0: DepositProcessed;
        };
    };
}

Full example:

type Pick2<T, K1 extends keyof T, K2 extends keyof T[K1]> = {
  [P1 in K1]: {
    [P2 in K2]: T[P1][P2];
  };
};

type DepositProcessed = { bla: 4 };

export type DepositProcessedByUserDoc = {
  trx: {
    _items: DepositProcessed[];
  };
};

export type GetDepositProcessedResult = Pick2<
  DepositProcessedByUserDoc,
  "trx",
  "_items",
  0
>;
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