Skip to content
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

Treat {} in T = {} as any in JS files #19977

Merged

Conversation

weswigham
Copy link
Member

This is mostly for cases like react, where the component type is defined with restrictive default props of {}, which while great for TS consumers, makes things difficult for JS users, and makes consuming JS react components inside TS difficult.

Fixes #19971

@@ -6454,7 +6454,10 @@ namespace ts {
}
for (let i = numTypeArguments; i < numTypeParameters; i++) {
const mapper = createTypeMapper(typeParameters, typeArguments);
const defaultType = getDefaultFromTypeParameter(typeParameters[i]);
let defaultType = getDefaultFromTypeParameter(typeParameters[i]);
if (defaultType && isTypeIdenticalTo(defaultType, emptyObjectType) && isJavaScriptImplicitAny) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would emptyTypeLiteralType equality check do the trick?

Copy link
Member Author

@weswigham weswigham Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any {} which has an alias symbol (like in react) would defeat that. IE,

type InternalMembers = {}

export class ComponentBase<P = InternalMembers> {}

@weswigham weswigham merged commit b3d3b78 into microsoft:master Nov 13, 2017
@weswigham weswigham deleted the empty-curly-defaults-as-any-in-js branch November 13, 2017 23:39
@weswigham
Copy link
Member Author

@mhegazy I know I've already merged, but as an improvement, should this production of any be flagged under noImplicitAny?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 14, 2017

i guess we should flag them all for consistency... that applies to {} in expression, and in inference as well.. though i have no idea how to report the inference implicit any

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants