Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
Operator precedence in typescript shorthand array notation: typeof unknown[]

In puppeteer's declaration file types.d.ts, I came across the following type definition:

  export declare type EvaluateFunc<T extends unknown[]>
      = (...params: InnerParams<T>) => Awaitable<unknown>;


  export declare type InnerParams<T extends unknown[]> = {
      [K in keyof T]: FlattenHandle<T[K]>;
  };

My question is in regards to <T extends unknown[]> and the operator precedence for typeof and [] .. is T extending unknown? Or is it extending unknown[], and, if it's the latter, then is the keyof operator able to be used on type Array? If so, does typescript take this to mean 'any numeric property of an array'? (aka, array item).

Assuming it's the former, and T is extending unknown, then how does the array shorthand [] operator affect the typeof operator? Just for context, here is the definition for FlattenHandle:

export declare type FlattenHandle<T> = T extends HandleOr<infer U> ? U : never;

Sub-question: export declare -- I've taken a break from TS for half a year and now that I'm back, I'm seeing these more and more. Is it a recent addition? What are we trying to say here? That, the type exists but was not exported in the source? One of the affects of this export declare is that my IDE (PHPStorm) thinks that the class ElementHandle exists, and even appears in console.log, but, if you Console.log(ElementHandle) you will get undefined:

export declare class ElementHandle<ElementType extends Node = Element> extends JSHandle<ElementType> {
    #private;
    // ...

Thank you for your help.

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda