-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
#49625 breaks node type expectations #49988
Comments
Hm, seems frustrating. #49625 came in after the beta - did we not see changes in DT from it though? |
microsoft/TypeScript#49625 improves handling of unions in type predicates so that unions are correctly preserved. This breaks types.isMap in node. For now I just changed the tests' expected type, but the type of isMap doesn't make much sense to me. It should probably be changed, but that's a much more complex task. This break is tracked at microsoft/TypeScript#49988 although it's correct, I think, so not very likely to be reverted.
Starting Saturday morning |
Also breaks is-object: declare function isObject(value: unknown): value is Record<string | symbol | number, unknown>;
const obj = {};
if (isObject(obj)) obj['attr']; I'm not sure why, but now |
Maybe I'm missing something, but isn't e.g. Playground Link (But, they don't seem to be identical enough to reduce in unions...) |
The visible difference in is-object's tests is that |
underscore's _.isFunction is also broken in a way I don't understand: declare var _: UnderscoreStatic;
interface UnderscoreStatic {
/**
* Returns true if `object` is a Function.
* @param object The object to check.
* @returns True if `object` is a Function, otherwise false.
**/
isFunction(object: any): object is Function;
}
const anyFunctionIteratee: _.Iteratee<any, string> = (element, key, collection) => {
element; // $ExpectType any
key; // $ExpectType any
collection; // $ExpectType any
return element.a;
};
type Iteratee<V, R, T extends TypeOfCollection<V, any> = TypeOfCollection<V>> =
CollectionIterator<T, R, V> |
string | number |
(string | number)[] |
Partial<T> |
null |
undefined;
interface CollectionIterator<T extends TypeOfList<V> | TypeOfDictionary<V, any>, TResult, V = Collection<T>> {
(element: T, key: CollectionKey<V>, collection: V): TResult;
}
if (_.isFunction(anyFunctionIteratee)) {
anyFunctionIteratee(recordDictionary['a'], 'a', recordDictionary); // $ExpectType string
} After #49625,
I don't understand what's happening here because |
One more from weak-napi: declare class WeakRef<T> {}
declare function weak<T extends object>(object: T, callback?: () => void): WeakRef<T>;
declare namespace weak {
/**
* Checks to see if ref is a dead reference. Returns true if the original Object has already been GC'd, false otherwise
* @param ref weak reference object
*/
function isDead(ref: WeakRef<any>): ref is WeakRef<undefined>;
}
const weakReference = weak({ a: 123 }, () => { });
if (weak.isDead(weakReference)) {
const a = weakReference; // $ExpectType WeakRef<undefined>
const value = weak.get(weakReference); // undefined only possible
} after, outside the if |
Regarding the The The In the |
* Update node types.isMap tests microsoft/TypeScript#49625 improves handling of unions in type predicates so that unions are correctly preserved. This breaks types.isMap in node. For now I just changed the tests' expected type, but the type of isMap doesn't make much sense to me. It should probably be changed, but that's a much more complex task. This break is tracked at microsoft/TypeScript#49988 although it's correct, I think, so not very likely to be reverted. * Change test for isSet too
Actions from the design meeting:
Let's continue to use this bug to track the improved handling of |
#49625 breaks node's type tests on DT.
Note that this causes node's
util
to return a union where it didn't before:But it's
ReadonlyMap<any, any> | Map<unknown, unknown>
now.I think this is correct, because the conditional type distributes and ReadonlyMap extends ReadonlyMap, while Record<any, any> doesn't. So the result is the union of the conditional's branches. However, this might turn out to be too big a breaking change for node, so I want to track it here.
@peterblazejewicz also noticed discussion at DefinitelyTyped/DefinitelyTyped#61353 on this change.
The text was updated successfully, but these errors were encountered: