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
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:
import Draft type from immer
Write function with Draft type
Build type declaration for the .ts file
import type { Draft } from 'immer'
export interface A {
a: number
}
export function draft(t: T): Draft {
return t as Draft
}
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): Draft;
// Here it uses raw A definition, which can be very long
export declare const draftA: {
a: number;
};
🐛 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 folderTo Reproduce
Steps to reproduce the behavior:
export interface A { a: number }
export function draft(t: T): Draft {
return t as Draft
}
const a: A = { a: 1, }
export const draftA = draft(a)
import type { Draft } from 'immer'; export interface A { a: number; } export declare function draft(t: T): Draft;
// Here it uses raw A definition, which can be very long
export declare const draftA: {
a: number;
};
import type { Draft, WritableDraft } from 'immer'; export interface A { a: number; } export declare function draft(t: T): Draft;
// Here it should be WritableDraft instead of raw definition of type A
export declare const draftA: WritableDraft;