Skip to content

Excess parameters create unsafe usage possibilities #18022

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
weswigham opened this issue Aug 24, 2017 · 2 comments
Closed

Excess parameters create unsafe usage possibilities #18022

weswigham opened this issue Aug 24, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@weswigham
Copy link
Member

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Just found a bug like this while editing our compiler - it would be super nice if we caught it.

Code

type AnonymousType = { kind: "anon", id: number, symbol: Symbol };
type UnionType = { kind: "union", id: number, types: Type[] };
type Type = UnionType | AnonymousType;
declare function forEach<T, U>(items: U[], cb: (item: U, index: number) => T): T;
declare function clone(symbol: Symbol): Symbol;
var someType: Type;
if (someType.kind === "anon") {
    addThingCallback(someType, clone(someType.symbol));
}
else {
    forEachType(someOtherType, addThingCallback);
}

function addThingCallback(t: Type, symbol?: Symbol) {
    if (symbol) {
        t.symbol = symbol;
    }
    t.id;
}

function forEachType<T>(type: UnionType, cb: (t: Type) => T) {
  return type && forEach(type.types, cb);
}

Expected behavior:
Either an error on the definition of forEachType warning about possible issues about overwritten parameters, or an error on the usage of addThingCallback with forEachType warning that it has excess arguments which may not be fulfilled by the specified type at runtime.
Actual behavior:
No error.

I feel like this is in the vein of improved checking that we've been doing with strict callback variance and excess property checks.

cc @rbuckton since you seemed interested - here's an issue to track it, and @sandersn, since you did work on the object literal checks.

@RyanCavanaugh
Copy link
Member

Duplicate #13043

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 8, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants