microsoft / microsoft/TypeScript
Constants + Generic causing TS4023 ("but cannot be named")
Abierto
@weswigham ya está trabajando en esto.
Desde el 13/4/2020.
Needs Investigation
Rescheduled
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.