-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preserve JSDoc comments attached to required properties (#837)
- Loading branch information
Showing
5 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"arktype": patch | ||
--- | ||
|
||
Make types keep JSDoc for required keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { describe, it } from "mocha" | ||
import { scope, type } from "../../src/main.js" | ||
|
||
const ab = { a: "1", b: 1 } | ||
describe("JSDoc", () => { | ||
// Note: `<#` are not checked, they are for understandability | ||
it("objects keep JSDoc", () => { | ||
type({ | ||
/** JSDoc */ | ||
a: "string" | ||
}).assert(ab).a // <# JSDoc | ||
}) | ||
it("intersections keep JSDoc", () => { | ||
type([ | ||
{ | ||
/** JSDoc */ | ||
a: "string" | ||
}, | ||
"&", | ||
{ | ||
b: "number" | ||
} | ||
]).assert(ab).a // <# JSDoc | ||
|
||
type([ | ||
{ | ||
/** First */ | ||
a: "string" | ||
}, | ||
"&", | ||
{ | ||
/** Second */ | ||
a: "string" | ||
} | ||
]).assert(ab).a // <# First | ||
|
||
scope({ | ||
a: { | ||
/** JSDoc */ | ||
a: "string" | ||
}, | ||
b: { | ||
b: "number" | ||
}, | ||
ab: "a & b" | ||
}) | ||
.compile() | ||
.ab.assert(ab).a // <# JSDoc | ||
}) | ||
|
||
it("works with module scopes", () => { | ||
scope({ | ||
/** JSDoc */ | ||
a: "string" | ||
}).compile().a // <# JSDoc | ||
}) | ||
|
||
it("doesn't work with optional keys", () => { | ||
type({ | ||
/** JSDoc */ | ||
"a?": "string" | ||
}).assert(ab).a // <# --- | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters