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

Reuse original type nodes even when part of the node is not usable #58515

Closed
6 tasks done
dragomirtitian opened this issue May 13, 2024 · 0 comments Β· Fixed by #58516
Closed
6 tasks done

Reuse original type nodes even when part of the node is not usable #58515

dragomirtitian opened this issue May 13, 2024 · 0 comments Β· Fixed by #58516

Comments

@dragomirtitian
Copy link
Contributor

πŸ” Search Terms

node reuse declarations

βœ… Viability Checklist

⭐ Suggestion

When tryReuseExistingTypeNodeHelper encounters an node it can't use, it will throw away the whole original node. We can instead fall back on type printing for only the subnode that is not reusable.

πŸ“ƒ Motivating Example

// @filename: a.ts
export const nImported = "nImported"
export const nNotImported = "nNotImported"
const nPrivate = "private"
export const o = (p1: typeof nImported, p2: typeof nNotImported, p3: typeof nPrivate) => null! as { foo: typeof nImported, bar: typeof nPrivate, baz: typeof nNotImported }

// @filename: b.ts
import { o, nImported } from "./a";
export const g = o
console.log(nImported);

// @filename: c.ts
import * as a from "./a";
export const g = a.o

Playgorund link

// currently generates
// @filename:c.d.ts
import { nImported } from "./a";
export declare const g: (p1: typeof nImported, p2: "nNotImported", p3: "private") => {
    foo: "nImported";
    bar: "private";
    baz: "nNotImported";
};

/// proposed
// @filename: c.d.ts
export declare const g: (p1: typeof a.nImported, p2: typeof a.nNotImported, p3: "private") => {
    foo: typeof a.nImported;
    bar: "private";
    baz: typeof a.nNotImported;
};

πŸ’» Use Cases

  1. What do you want to use this for? - Improve declaration fidelity and speed
  2. What shortcomings exist with current approaches? - Throwing away the type node can happen half way through resulting in duplicate work.
  3. What workarounds are you using in the meantime?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant