-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Static method" or properties on functions gives rise to issue #22408
Comments
We do this sort of inference in JavaScript now; see #21974 For TypeScript it's a bit less obvious because we don't want every property write to be equivalent to a property declaration, so it becomes an exercise in dividing up the gray areas into "You tried to write to a non-existant property (error)" and "You intended to declare a new property via an assignment". |
I'd be wary of implicit property declarations in TypeScript, because they would mask a common source of errors (ie typos) that TypeScript currently catches. I think its better to keep some explicit syntax difference so TS can continue to distinguish between new property declarations and plain old typos. |
Also this seems to be covered by #15868. @RyanCavanaugh you already approved that one 😁. |
We're pretty skeptical (in the classical sense) of implicit property declarations, but there are a few places where it seems safe. For example, immediately following a function declaration or function-expression-initialized |
Ah look at that |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I looked for duplicates, perhaps this is related?
#5863
Not sure...
Suppose we have some
IO
function that returns an object. In Javascript, Classes are more or less just functionsThe
of
class function raises an issue withProperty 'of' does not exist on type '(f: any) => { f: any; map: (g: any) => any; join: () => any; }'.
Expected behavior is that TS understands that
of
is a property or "static method" of sorts on the IO function.The error goes away by doing one of the following
Or something like this
It seems that
of
should be inferred without this however. Also, in the later example, Intellisense doesn't seem to realize thatmap
return a new copy ofP
interface but that is probably news for a different team ;-)The text was updated successfully, but these errors were encountered: