mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Remove only undefined, not null | undefined, from declared type
This commit is contained in:
@@ -10929,7 +10929,7 @@ namespace ts {
|
||||
declaration.initializer &&
|
||||
getFalsyFlags(declaredType) & TypeFlags.Undefined &&
|
||||
!(getFalsyFlags(checkExpression(declaration.initializer)) & TypeFlags.Undefined);
|
||||
return annotationIncludesUndefined ? getNonNullableType(declaredType) : declaredType;
|
||||
return annotationIncludesUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
|
||||
}
|
||||
|
||||
function checkIdentifier(node: Identifier): Type {
|
||||
|
||||
@@ -27,6 +27,13 @@ function foo4(x: string | undefined = undefined, b: number) {
|
||||
x = undefined;
|
||||
}
|
||||
|
||||
type OptionalNullableString = string | null | undefined;
|
||||
function allowsNull(val: OptionalNullableString = "") {
|
||||
val = null;
|
||||
val = 'string and null are both ok';
|
||||
}
|
||||
allowsNull(null); // still allows passing null
|
||||
|
||||
|
||||
|
||||
// .d.ts should have `string | undefined` for foo1, foo2, foo3 and foo4
|
||||
|
||||
Reference in New Issue
Block a user