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

Detect deeper change in function parameters #222

Closed
academo opened this issue Oct 18, 2022 · 0 comments · Fixed by #361
Closed

Detect deeper change in function parameters #222

academo opened this issue Oct 18, 2022 · 0 comments · Fixed by #361
Labels
enhancement New feature or request

Comments

@academo
Copy link
Member

academo commented Oct 18, 2022

Currently levitate can detect trivial type changes in function parameters such as the following cases:

function old(x:number, y:string) {}
function new(x:number, y:number) {} //detect change in `y`

Or when using an interface or type:

// old
type params = {
   x: number;
   y: string;
}
function old({x, y}: params) {}


// new
type params = {
   x: number;
   y: number; // detects change in `y`
}
function new({x, y}: params) {}

But it will fail to recognize changes in more complex types such union, extensions, or in anyway processed like: Omit, Pick, etc..

example:

// old
type parentType = {
   x: number;
}

type params = parentType & { y: string};

function old({x, y}: params) {}

// new
type parentType = {
   x: string; // it won't detect `x` changed to `string`
}

type params = parentType & { y: string};

function new({x, y}: params) {}

Ideas:

There are some "hidden" APIs inside the typescript compiler that make the task of identifier changes in these complex types somehow easier: isAssignableTo, isComparableTo But they are not public and there's not much traction to make them available (see microsoft/TypeScript#9879).

Some packages such as https://github.com/SamVerschueren/tsd-typescript or https://github.com/skarab42/unleashed-typescript patch or replace typescript to expose those APIs. We could use one of those packages to access the internal APIs and detect changes.

The challenge after that is to create a human-readable diff of those types, specially in very complex ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant