microsoft / microsoft/TypeScript

Constants + Generic causing TS4023 ("but cannot be named")

Aperta
#37,888 8 commenti 9 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 13/4/2020.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

TypeScript Version: 3.8, but also the 3.9 beta

Search Terms: ts4023 cannot be named constant

Code

Create a tsconfig with declaration: true. Then, in main.ts:

import {StructType} from './lib';

declare function foo<T>(): T;

export const exportedFooFunc = foo<StructType>();

In lib.ts:

export const SOME_CONSTANT = 'fieldKey';

export type MakeStruct<S> = S;
export type StructType = MakeStruct<{
    readonly [SOME_CONSTANT]: any;
}>;

Old instructions (don't repro anymore)

Create a tsconfig with declaration: true. Then, in main.ts:

import {
    ReturnType1,
    ReturnType2,
} from './lib';

export const impl1 = (): ReturnType1 => ({
});

export const impl2 = (): ReturnType2 => ({
});

In lib.ts:

export const SOME_CONSTANT = 'myConstant';

export type WrapType<S> = S;

export type ReturnType1 = WrapType<{
    [SOME_CONSTANT]?: {};
}>;

export type ReturnType2 = {
    [SOME_CONSTANT]?: {};
};

Expected behavior:

The file should be properly compiled.

Actual behavior:

TypeScript reports a diagnostic:

Exported variable 'exportedFooFunc' has or is using name 'SOME_CONSTANT' from external module "/.../lib" but cannot be named.

Playground Link: n/a

Related Issues: n/a

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.