-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Regression in type inference from 2.5 -> 2.6 #19668
Comments
I'm getting lots of errors when I compile the example (after installing the referenced npm modules). In particular, many of the errors relate to the fix implemented in #17922. It appears the |
Right, compiling with tsc does indeed show type errors in the library, in VSCode it does not show them. @hediet, can you look into it? |
Is there an easy way to properly type generic classes that extend from a class expression? The use-case is Immutable.js's Common: interface NodeProps<N> {
value: N;
edges: List<string>;
} Here's what I want to do: export class Node<N> extends Record<NodeProps<N>>(defaultNode) {
setValue(value: N): Node<N> {
return this.set("value", value as never);
}
} Unfortunately this gives me interface NodeMethods<N> {
setValue(value: N): Node<N>;
}
class NodeBase<N> extends Record<NodeProps<any>>(defaultNode) implements NodeMethods<N> {
setValue(value: N): Node<N> {
return this.set("value", value);
}
}
export type Node<N> = Readonly<NodeProps<N>> & NodeMethods<N> & Record<NodeProps<N>>;
export function Node<N>(values: Partial<NodeProps<N>>): Node<N> {
return new NodeBase(values);
} Is there a better way to go about this? Edit: Sorry if this belongs to #17829 |
|
I'm using version export function Factory<TProps extends Object>(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
export function Record<TProps>(defaultValues: TProps, name?: string): Record.Factory<TProps>; Extending from Here's a minimal repro that (unlike export function MyRecord<T>() {
return class {
value: T;
};
}
export class Foo<T> extends MyRecord<T>() {} |
Ah, I see, I though you were referencing TypeScript's built in export function MyRecord<T = any>() {
return class {
value: T;
};
}
export class Foo<T> extends MyRecord() {} to obtain an approximation of the old behavior. Or write export function MyRecord() {
return class<T> {
value: T;
};
}
export class Foo<T> extends MyRecord()<T> {}
const foo = new Foo<string>();
foo.value.toLocaleLowerCase(); to pass the type parameter to the expression that results from calling the class factory. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.6.0-rc, 2.7.0-dev.20171101
Code Runnable Gist
Expected behavior:
Correctly inferred type of
test()
(Typescript 2.5.3):Actual behavior:
2.6.0-rc:
2.7.0-dev.20171029:
No type errors are shown in either version.
The text was updated successfully, but these errors were encountered: