Skip to content

Apply TS2713 to classes#20335

Merged
amcasey merged 3 commits into
microsoft:masterfrom
amcasey:TS2713
Nov 30, 2017
Merged

Apply TS2713 to classes#20335
amcasey merged 3 commits into
microsoft:masterfrom
amcasey:TS2713

Conversation

@amcasey
Copy link
Copy Markdown
Member

@amcasey amcasey commented Nov 29, 2017

Formerly, they were excluded as values, but the error is just as
relevant for classes.

Note that it is not applied to enums since switching to an indexed
access expression will not help for an enum.

Formerly, they were excluded as values, but the error is just as
relevant for classes.

Note that it is not applied to enums since switching to an indexed
access expression will not help for an enum.
Comment thread src/compiler/checker.ts Outdated
function checkAndReportErrorForUsingTypeAsNamespace(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
if (meaning === SymbolFlags.Namespace) {
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.TypeAlias, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
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.

It seems like type aliases might already have been resolved by this point, so I'm not sure the flag makes any difference.

Copy link
Copy Markdown
Member

@DanielRosenwasser DanielRosenwasser Nov 29, 2017

Choose a reason for hiding this comment

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

What about type parameters etc?

function foo<T extends { abc: number }>(x: T) {
    let a: T.abc = x.abc;
    //     ~~~~~
}

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.

I was (incorrectly) thinking of a nominal type system in which it would be preferable to just use the name of the base type to get at the property.

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.

Can you please elaborate on "etc"? Are there other values that make sense?

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.

Offline, we settled on SymbolFlags.Type & ~SymbolFlags.Namespace.

@amcasey amcasey merged commit cdd3cd4 into microsoft:master Nov 30, 2017
@amcasey amcasey deleted the TS2713 branch November 30, 2017 01:39
@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.

3 participants