Skip to content

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

Merged
Wesley Wigham (weswigham) merged 1 commit into
microsoft:masterfrom
weswigham:empty-curly-defaults-as-any-in-js
Nov 13, 2017
Merged

Wesley Wigham (weswigham) merged 1 commit into
microsoft:masterfrom
weswigham:empty-curly-defaults-as-any-in-js

Conversation

@weswigham

Copy link
Copy Markdown
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

Comment thread src/compiler/checker.ts
const mapper = createTypeMapper(typeParameters, typeArguments);
const defaultType = getDefaultFromTypeParameter(typeParameters[i]);
let defaultType = getDefaultFromTypeParameter(typeParameters[i]);
if (defaultType && isTypeIdenticalTo(defaultType, emptyObjectType) && isJavaScriptImplicitAny) {

Copy link
Copy Markdown
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?

@weswigham Wesley Wigham (weswigham) Nov 13, 2017 •

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

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

@mhegazy

Copy link
Copy Markdown
Contributor

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 (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