diff --git a/src/analysis/env_builder/eq_test.ml b/src/analysis/env_builder/eq_test.ml index ad22ef2c58c..d06b878ea94 100644 --- a/src/analysis/env_builder/eq_test.ml +++ b/src/analysis/env_builder/eq_test.ml @@ -147,6 +147,20 @@ module Make ) -> literal_check_of_expr value |> Base.Option.value_map ~default:acc ~f:(fun check -> SMap.add name check acc) + | ( _, + Init + { + key = + Ast.Expression.Object.Property.NumberLiteral + (_, { Ast.NumberLiteral.value = key_value; _ }); + value; + shorthand = _; + } + ) + when Js_number.is_float_safe_integer key_value -> + let name = Dtoa.ecma_string_of_float key_value in + literal_check_of_expr value + |> Base.Option.value_map ~default:acc ~f:(fun check -> SMap.add name check acc) | _ -> acc) | Ast.Expression.Object.SpreadProperty _ -> acc ) diff --git a/tests/contextual_typing/sentinel_refinements.js b/tests/contextual_typing/sentinel_refinements.js index dae152a1021..79150e14e6d 100644 --- a/tests/contextual_typing/sentinel_refinements.js +++ b/tests/contextual_typing/sentinel_refinements.js @@ -64,3 +64,9 @@ function function_statics() { ... } = x => {}; // okay `x` inferred as `mixed` } + +// Numeric literal key names +type B = {0: 'a', f: (string) => string} | {0: 'b', f: number => number}; +{ + const b: B = {f: (v) => (v as string), 0: 'a'}; // OK +}