Skip to content

TypeScript 2.5 "unused type parameter" breaks existing code #18370

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

Closed
benny-medflyt opened this issue Sep 10, 2017 · 5 comments
Closed

TypeScript 2.5 "unused type parameter" breaks existing code #18370

benny-medflyt opened this issue Sep 10, 2017 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@benny-medflyt
Copy link

TypeScript Version: 2.5.2

Code

type Foo<s> = object;

This worked fine in TypeScript 2.4, but causes the following error in 2.5.2:

error TS6133: 's' is declared but never used.

This change in TypeScript is breaking massive amounts of code that use phantom type parameters. And there doesn't seem to be any workaround.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Sep 10, 2017
@RyanCavanaugh
Copy link
Member

You can turn off no unused variables, or name them with a leading underscore (Foo<_s> will not cause an error).

@benny-medflyt
Copy link
Author

I tried adding a leading underscore:

type Foo<_s> = object;

Still causes the same error ('s' is declared but never used.)

Switching off noUnusedLocals does work, but at the great expense of loosing that feature

@gcnew
Copy link
Contributor

gcnew commented Sep 11, 2017

I'm interested in what you use phantom type parameters for, as they are not enforced by the compiler. If a type parameter is not referenced in the type's body, it's not considered during checking.

@benny-medflyt
Copy link
Author

benny-medflyt commented Sep 11, 2017

I'm interested in what you use phantom type parameters for, as they are not enforced by the compiler. If a type parameter is not referenced in the type's body, it's not considered during checking.

You are right, it turns out that the code in the style above was actually from some older experiments with phantom types, that we don't actually use.

The way we actually use phantom types with correct type checking is by adding a dummy field:

export class Q<s> {
    protected dummy: [Q<s>, s];
}

Relevant: #202 #5855

@RyanCavanaugh
Copy link
Member

Logged #18420

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants