microsoft / microsoft/TypeScript

Incorrectly inferred object property as string literal value

Abierto
#39,131 3 comentarios 1 reacción 1 asignado Ver en GitHub

@RyanCavanaugh ya está trabajando en esto.

Desde el 29/6/2020.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

TypeScript Version: 3.9.2

Search Terms:
incorrectly inferred string index type
inferred object property in function return type

Expected behavior:
The key values in each Variation should be inferred as string not the literal string value

Actual behavior:
The key values in each Variation are inferred as the literal string value of the first object

Related Issues:
Possibly related: https://github.com/microsoft/TypeScript/issues/38759,

Code


type Variation = {
    [testDescription: string]: () => void;
}

export type VariationProvider = {
  variations: Variation[];
};

export type VariationProviderFactory = (extras: object) => VariationProvider;

export function createVariationProvider(factory: VariationProviderFactory) {
  return factory;
}


createVariationProvider(() => {
  return {
    variations: [
      {
        foo: () => {}
      },
      {
        broken: () => {}
      },
    ]
  }
})

Output
export function createVariationProvider(factory) {
    return factory;
}
createVariationProvider(() => {
    return {
        variations: [
            {
                foo: () => { }
            },
            {
                broken: () => { }
            },
        ]
    };
});

Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.