microsoft / microsoft/TypeScript

TS4055 when generating declaration for return type that uses type of paramter for protected methods

Aperta
#61,591 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Declaration Emit Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

🔎 Search Terms

TS4055 declaration protected return typeof parameter

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about declarations
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.3#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgBSgjDRgWAGc4BvAKDjjCJNgE8BBALjiQFcBbAEZoA3PUbNSrAELcKMKMgDmYgL61aoSLDjpeSbGQhI4S4DELEpANUwAbXsAD6AeQDWACnFMrschW5LFjJKABpvSTYAOUx+YG43YFYIdAJIkIpwgEpA9P8AbRhWEhSJXyKYuIBdGnEoc14oEx9ggpapSuAqtQ0taHhsO0wKKnZahjBeQTsEbFNzIJt7R1dPcQm8ylzy-3CGDfLWToSk0sW-MPEctJ3KQuLgUvbo2K7x-fqYRubNinzniqvbridTiAD0YLgaCIUDgABUAMoAFgADABWNHcABKDSacCKJDgTymMzmcRgAAsIAATXREfhQ8D9YC0wbDKgU4ZE2EIKi8CjKCQIABumFQPFecAA5ACjq8pQA6CIQVCGFnzCzpVi2BzOACiUBhXn2ZVaWxuZsy61NHVeJ2SqXOGT2cGuToKBMeqVlnRqdBNn2+Noufx9QLEDFBDAhUMN0HhyJRAHYAMyBTBQV6oWEyrU6xxSonekmzODkqm09D0xnaVCsoYjOCcqjx3lwfmCpgisV4JCS3OHTqK5WqutwCgLPPLfVxqDG-YA-zbS0ug7BOVxe1nX6r4NFfPxC2kD0PJ5a30urLvaOQuEuAAiLhBtHUQA

💻 Code
export interface Properties {
  propertyA: number;
  propertyB: string;
}

export function getPropertyValue_Ok(
  properties: Properties,
  propertyName: keyof Properties,
): Properties[typeof propertyName] {
  return properties[propertyName];
}

export class A {
  public getPropertyValue_Ok(
    properties: Properties,
    propertyName: keyof Properties,
  ): Properties[typeof propertyName] {
    return properties[propertyName];
  }

  // error TS4055: Return type of public method from exported class has or is using private name 'propertyName'.
  protected getPropertyValue_Error(
    properties: Properties,
    propertyName: keyof Properties,
  ): Properties[typeof propertyName] {
    return properties[propertyName];
  }

  // error TS4073: Parameter 'propertyValue' of public method from exported class has or is using private name 'propertyName'.
  protected setPropertyValue_Error(
    properties: Properties,
    propertyName: keyof Properties,
    propertyValue: Properties[typeof propertyName],
  ) {
    // TODO
  }
}
🙁 Actual behavior

The protected methods fail to generate declaration with TS4055 or TS4073.

🙂 Expected behavior

The protected methods should be able to generate declaration similar to the public method or function.

Additional information about the issue

I wonder if there's a way to temporarily suppress this error, becuase ts-ignore doesn't seem to work when generating declaration.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il TypeScript Playground collegato e la riproduzione fornita per la generazione delle dichiarazioni, concentrandoti sui metodi protetti di class A e sulle diagnostiche TS4055/TS4073. Confronta il loro comportamento con quello del metodo pubblico e della funzione indipendente; il lavoro è completato quando la generazione delle dichiarazioni riesce per i metodi protetti senza questi errori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.