Skip to content

Commit

Permalink
- removes redundant undefined qualifier in TypeScript for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Sep 18, 2023
1 parent bdd85a1 commit 5f2cb2c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Localhost based descriptions are not cached anymore to facilitate development workflows. [#3316](https://github.com/microsoft/kiota/issues/3316)
- Removed redundant undefined qualifier in TypeScript for properties. [#3244](https://github.com/microsoft/kiota/issues/3244)

## [1.6.1] - 2023-09-11

Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Writers/TypeScript/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w

private static void WriteCodePropertyForInterface(CodeProperty codeElement, LanguageWriter writer, string returnType, bool isFlagEnum)
{
writer.WriteLine($"{codeElement.Name.ToFirstCharacterLowerCase()}?: {returnType}{(isFlagEnum ? "[]" : string.Empty)}{(codeElement.Type.IsNullable ? " | undefined" : string.Empty)};");
writer.WriteLine($"{codeElement.Name.ToFirstCharacterLowerCase()}?: {returnType}{(isFlagEnum ? "[]" : string.Empty)};");
}

private void WriteCodePropertyForClass(CodeProperty codeElement, CodeClass parentClass, LanguageWriter writer, string returnType, bool isFlagEnum)
Expand All @@ -45,7 +45,7 @@ private void WriteCodePropertyForClass(CodeProperty codeElement, CodeClass paren
writer.CloseBlock();
break;
default:
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {codeElement.NamePrefix}{codeElement.Name.ToFirstCharacterLowerCase()}{(codeElement.Type.IsNullable ? "?" : string.Empty)}: {returnType}{(isFlagEnum ? "[]" : string.Empty)}{(codeElement.Type.IsNullable ? " | undefined" : string.Empty)};");
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {codeElement.NamePrefix}{codeElement.Name.ToFirstCharacterLowerCase()}{(codeElement.Type.IsNullable ? "?" : string.Empty)}: {returnType}{(isFlagEnum ? "[]" : string.Empty)};");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void WritesCustomProperty()
property.Kind = CodePropertyKind.Custom;
writer.Write(property);
var result = tw.ToString();
Assert.Contains($"{PropertyName}?: {TypeName} | undefined", result);
Assert.Contains($"{PropertyName}?: {TypeName}", result);
Assert.DoesNotContain("| undefined", result); // redundant with ?
}
[Fact]
public void WritesFlagEnums()
Expand Down

0 comments on commit 5f2cb2c

Please sign in to comment.