-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 3.5.1
Search Terms:
- 2739
- function properties block
- top level function
Code
interface Person {
first: string;
last: string;
}
const dice = () => Math.floor(Math.random() * 6);
dice.first = 'Rando';
dice.last = 'Calrissian';
const diceP: Person = dice; // OK
// but inside a block...
{
const dice = () => Math.floor(Math.random() * 6);
dice.first = 'Rando'; // Property 'first' does not exist on type '() => number'.
dice.last = 'Calrissian'; // Property 'last' does not exist on type '() => number'.
const diceP: Person = dice; // Type '() => number' is missing the following properties from type 'Person': first, last
}
Expected behavior:
I would expect the same behavior both inside and outside the block.
Actual behavior:
Assigning properties to a function at the top level is allowed, but not inside a block. Frankly, I'm impressed that the first example works at all. But I don't see why they would be different!
Playground Link: link
Related Issues:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue