You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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: 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
The text was updated successfully, but these errors were encountered:
🐛 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:
Observed behavior
The generated type declaration file is:
Expected behavior
Environment
immer@^10
The text was updated successfully, but these errors were encountered: