Closed
Description
TypeScript Version: nightly (2.6.0-dev.20170829)
Code
type Point = { x: number, y: number }
type Mapped = Record<'x'|'y', number>
type IndexSignature = { [x: string]: never }
// All of the following have type: `() => Object`
type Test1 = Point['valueOf']
type Test2 = Mapped['valueOf']
type Test3 = IndexSignature['valueOf']
Expected behavior:
Test1
, Test2
and Test3
should all be errors.
User provided types should be considered "exact". No properties should be inherited from Object
. The current behaviour is of little use, however it's quite confusing and really gets in the way of type level programming.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Global object properties should not surface on type level indexing[/-][+][Suggestion] Global object properties should not surface on type level indexing[/+]gcnew commentedon Aug 29, 2017
The magic
Object
keys are not present inkeyof
expressions, causing non-uniform behaviour:olegdunkan commentedon Aug 30, 2017
#16578 (comment)
mhegazy commentedon Nov 7, 2017
It is consistent with other uses of indexing.. e.g. indexing with numbers..
keyof T
will return you only string, public, and own properties. I would argue that this is exactelly what you want.. you do not wanttoString
to start showing up in allkeyof T
... that would be too verbose, and would be a breaking change..On the flip side, not having it in
keyof T
does not change the fact thattoString
exists on all objects.. this is in a sense similar to indexing with numbers.typescript-bot commentedon Nov 21, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.