-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Non-exported recursive type alias is inlined until it falls back to any in declarations #58696
Comments
Generally, I feel like it'd be even better to always emit some sort of declaration error whenever declaration emit synthesizes an |
I'll open a PR after 5.5. I tried locally and there are several places that now have errors, but in my opinion they are all good. Maybe we have just a carveout if someone is not using |
I think this is the same issue I'm having, but I'm not sure. Problem description within...// Exported from `@mylib/dev/jrfs`:
export interface FileOf<D = unknown, M = unknown> {
data: D;
meta: M;
}
export type FileTypes<FT> = Record<keyof FT & string, FileOf>;
// Exported from `@mylib/dev/features/db`:
export interface DbDesign {
db: DbModel;
}
export interface DbDesignFileMeta {
test: boolean;
}
export type DbDesignFile = FileOf<DbDesign, DbDesignFileMeta>; In the app project which imports from import { DbDesignFile } from "@mylib/dev/features/db";
interface ProjectFileTypes {
db: DbDesignFile;
}
// Try it out:
class Yada<FT extends FileTypes<FT>> {
async findTypes<K extends keyof FT & string>(
type: K,
): Promise<
Array<{
node: any;
data: Required<FT[K]>["data"];
}>
> {
return [];
}
}
const yada = new Yada<ProjectFileTypes>();
const nodes = await yada.findTypes("db");
for (const { node, data } of nodes) {
// TODO: Figure out why `data` is treated like `any` here:
console.log("FOUND", node.name, data);
} However, if I re-define the DbDesignFile type alias in my app project then import { FileOf } from "@mylib/dev/jrfs";
import { DbDesign, DbDesignFileMeta } from "@mylib/dev/features/db";
type DbDesignFile= FileOf<DbDesign, DbDesignFileMeta>;
interface ProjectFileTypes {
db: DbDesignFile;
} UPDATE: I figured out my own issue - my library's type declarations were being created with |
π Search Terms
declarations recursive types
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
In declarations, the type for
a
is printed asa: () => T extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? any : V : V : V : V : V : V : V : V : V : V : T;
π Expected behavior
Recursive
can't be represented without falling back toany
(as seen above) so it should just be an error instead of silently toany
Additional information about the issue
Related to #55832
The text was updated successfully, but these errors were encountered: