Open ExE-Boss opened 3 years ago
Another example:
type Widget = {name:string};
const widgets: Widget[] = [
{name: 'gear'},
{name: 'bearing'},
{name: 'axle'}
];
const workingReadonlyWidgets = Readonly<Widget>[] = widgets.map(
w => Object.freeze(w)
);
const brokenReadonlyWidgets = Readonly<Widget>[] = widgets.map(
Object.freeze
); // this line complains
:wave: Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
Issue body code block by @ExE-Boss
:warning: Assertions:
const FEATURES: readonly Readonly[]
Version | Reproduction Outputs |
---|---|
4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2 |
:warning: Assertions:
|
Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
A generic transforming function (e.g.:
Object.freeze
) passed as a callback to a generic mapping function (such asArray.prototype.map
), should be handled similarly to an arrow function with inferred types.📃 Motivating Example
From engine262/src/engine.mjs:
Workbench Repro
Expected type:
Like when using an arrow function:
```ts repro // @target: ES2015 // @filename: index.ts export const ARROW_FEATURES = Object.freeze([ // ^? { name: 'Top-Level Await', flag: 'top-level-await', url: 'https://github.com/tc39/proposal-top-level-await', }, { name: 'Hashbang Grammar', flag: 'hashbang', url: 'https://github.com/tc39/proposal-hashbang', }, { name: 'RegExp Match Indices', flag: 'regexp-match-indices', url: 'https://github.com/tc39/proposal-regexp-match-indices', }, { name: 'FinalizationRegistry.prototype.cleanupSome', flag: 'cleanup-some', url: 'https://github.com/tc39/proposal-cleanup-some', }, { name: 'Arbitrary Module Namespace Names', flag: 'arbitrary-module-namespace-names', url: 'https://github.com/tc39/ecma262/pull/2154', }, { name: 'At Method', flag: 'at-method', url: 'https://github.com/tc39/proposal-item-method', }, ].map((feature) => Object.freeze(feature))); ``` [Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?target=2&lib=#code/PTAEAEBcEMCcHMCmkBcoCiBlATABgIwCsAUCBAGYCWANogHbQC2ialdAJogB4B0kAzsW4AHAPaxIoAMai6-SQEEASkoDyAdQD6AMXQKAKgFUlWUAF5QqgEYArRFMg9ysRIgBeiABQBtUmFABgUHBIaAAegD8xACQAN4x0QzMaADk+qLCALQAMogAbojUoAoA7tCUkCkANAnk1NDwqZAZmbQF1JnQZRXVCQCusNSpABaQkML8KCDwFcN9VjwyjMCQUgDMAJzAwrAZovzQHc1ZbYWd3ZU10QC+V-HRiUwsoCkAEtD8w1bQdPCgAOKwJiMOC9B51BojD5fH7wMHRAZDF6jcaTaazeaLUTLVabba7MQHDrDaHfX5g24xe6PZIvJSIeDoLjCUAAWWgq2GoAAkhxKFJEPx4RDGi8XEhmZkQZzMmx2PzBfDESMxhMpsAZpA5gslit1lsdnsiZlxSIpRypMNZXyBUKrpS4gkks8Uto2IdKG4OZRZPSZvJYABPHiG5qQQPCRCLWg-PrCTDYxDC+qilJSGN0OOZfiJpWDFWo9Wa7VYnH6-FGw6ZdOIWNZHPMCl3J1PVIKWBWCpAoNs0TsPq0UAAOSe-GE0AFw9HychLzgncg3cDUr7A8QmWdY4n683eaRKRRavRWsxutxW3sIOwADZsNsB9RgNgiAAWJtUlu0lIKSSs5DDPsZ1TDkpX-QCrgRfNkVVNENQxHVsT1PFDUJKsKkQRhQK1cCYkpABdHgQWETxPHIWtIAGRAAEpzAAPksWx7EcZxXA8UjyMoqiuIAbmIIA)Actual type:
💻 Use Cases
Getting correct type inference for JavaScript code on the wild web.
Related issues