You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Form spec:
The apparent members of an object type T are the combination of the following:
The declared and/or inherited members of T.
The properties of the global interface type 'Object' that aren't hidden by properties with the same name in T.
If T has one or more call or construct signatures, the properties of the global interface type 'Function' that aren't hidden by properties with the same name in T.
Actual behavior:
Error.
If it by design I am with great pleasure would like to know what is permitted property names?
Would you mind if ask a question.
Spec doesn't define a notion of the apparent type, only apparent members .
From spec: The apparent members of the primitive type String and all string literal types are the apparent members of the global interface type 'String'
I can assume from spec that the global interface String is a apparent type if so then the global interface type 'Function' is also a apparent type.
For global interface String it works, but for the global Function doesn't !!!
check("","atChar");//ok
The question is what is the apparent type, what is a difference between String and Function and more interesting what is a motivation to differ (Number, String and Boolean) and (Object, Function) global interfaces in the context of the keyof type query?
I have made some investigations.
From tsc code follows that the apparent type of type T is {} except:
for string is global interface String,
for number is global interface Number,
for boolean is global interface Boolean,
for type parameter is constraint, if any,
...
The motivation to differ (Number, String and Boolean) and (Object, Function) is probably to prevent enumerating of native (intrinsic) properties of Object and Function for user types.
Activity
ahejlsberg commentedon Jun 16, 2017
This is by design. The
keyofoperator only considers the declared or inherited properties of a type, not those that come from its apparent type.olegdunkan commentedon Jun 16, 2017
Anders Hejlsberg (@ahejlsberg) ok, thanks.
Would you mind if ask a question.
Spec doesn't define a notion of the apparent type, only apparent members .
From spec:
The apparent members of the primitive type String and all string literal types are the apparent members of the global interface type 'String'
I can assume from spec that the global interface
Stringis a apparent type if so then the global interface type 'Function' is also a apparent type.For global interface
Stringit works, but for the globalFunctiondoesn't !!!The question is what is the apparent type, what is a difference between
StringandFunctionand more interesting what is a motivation to differ (Number,StringandBoolean) and (Object,Function) global interfaces in the context of thekeyoftype query?olegdunkan commentedon Jun 17, 2017
I have made some investigations.
From
tsccode follows that the apparent type of typeTis{}except:for
stringis global interface String,for
numberis global interface Number,for
booleanis global interface Boolean,for
type parameteris constraint, if any,...
The motivation to differ (Number, String and Boolean) and (Object, Function) is probably to prevent enumerating of native (intrinsic) properties of
ObjectandFunctionfor user types.