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

type WritableDraft is not exported anywhere in dist, this causes build type declaration files with Draft finally fall back to raw and causing the type declaration exceeds max token length #1115

Closed
1 task done
JodoZT opened this issue Apr 11, 2024 · 0 comments

Comments

@JodoZT
Copy link
Contributor

JodoZT commented Apr 11, 2024

🐛 Bug Report

A clear and concise description of what the bug is.
When using Draft with object type in our code and build type declaration files from tsc, it will extract the T object type to raw object type because the WritableDraft is not exported from immer dist.

Link to repro

A bug report without a reproduction is not a bug report. Failing to follow this templately is likely to result in an immediate close & lock of the issue.

CodeSandbox link
Run pnpm run build-types to build type declarations to types folder

To Reproduce

Steps to reproduce the behavior:

  1. import Draft type from immer
  2. Write function with Draft type
  3. Build type declaration for the .ts file
import type { Draft } from 'immer'

export interface A {
  a: number
}

export function draft<T>(t: T): Draft<T> {
  return t as Draft<T>
}

const a: A = {
  a: 1,
}

export const draftA = draft(a)

Observed behavior

The generated type declaration file is:

import type { Draft } from 'immer';
export interface A {
    a: number;
}
export declare function draft<T>(t: T): Draft<T>;
// Here it uses raw A definition, which can be very long
export declare const draftA: {
    a: number;
};

Expected behavior

import type { Draft, WritableDraft } from 'immer';
export interface A {
    a: number;
}
export declare function draft<T>(t: T): Draft<T>;
// Here it should be WritableDraft<A> instead of raw definition of type A
export declare const draftA: WritableDraft<A>;

Environment

immer@^10

  • Immer version:
  • I filed this report against the latest version of Immer
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

No branches or pull requests

1 participant