-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for named tupple members
fix: broken code of conduct documentation link fix: code style formatting fix: corrected error message
- Loading branch information
1 parent
aad6e59
commit f49d0b2
Showing
10 changed files
with
176 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ts from "typescript"; | ||
import { Context, NodeParser } from "../NodeParser"; | ||
import { SubNodeParser } from "../SubNodeParser"; | ||
import { AnnotatedType } from "../Type/AnnotatedType"; | ||
import { ArrayType } from "../Type/ArrayType"; | ||
import { BaseType } from "../Type/BaseType"; | ||
import { ReferenceType } from "../Type/ReferenceType"; | ||
import { RestType } from "../Type/RestType"; | ||
|
||
export class NamedTupleMemberNodeParser implements SubNodeParser { | ||
public constructor(protected childNodeParser: NodeParser) {} | ||
|
||
public supportsNode(node: ts.TypeNode): boolean { | ||
return node.kind === ts.SyntaxKind.NamedTupleMember; | ||
} | ||
|
||
public createType(node: ts.NamedTupleMember, context: Context, reference?: ReferenceType): BaseType | undefined { | ||
const baseType = this.childNodeParser.createType(node.type, context, reference); | ||
|
||
if (baseType instanceof ArrayType && node.getChildAt(0).kind === ts.SyntaxKind.DotDotDotToken) { | ||
return new RestType(baseType, node.name.text); | ||
} | ||
|
||
return baseType && new AnnotatedType(baseType, { title: node.name.text }, false); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type MyNamedUniformTuple = [first: string, second: string]; | ||
|
||
export type MyNamedTuple = [first: string, second: number]; | ||
|
||
export type MyUniformTupleWithRest = [first: number, second: number, ...third: number[]]; | ||
|
||
export type MyTupleWithRest = [first: string, second: number, ...third: string[]]; | ||
|
||
export type MyNestedArrayWithinTuple = [first: string, second: number, third: string[]]; | ||
|
||
export type MyNestedArrayWithinTupleWithRest = [first: string, second: number, ...third: string[][]]; |
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,114 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyNamedUniformTuple": { | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "string" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "string" | ||
} | ||
], | ||
"minItems": 2, | ||
"maxItems": 2, | ||
"type": "array" | ||
}, | ||
"MyNamedTuple": { | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "string" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "number" | ||
} | ||
], | ||
"maxItems": 2, | ||
"minItems": 2, | ||
"type": "array" | ||
}, | ||
"MyUniformTupleWithRest": { | ||
"additionalItems": { | ||
"title": "third", | ||
"type": "number" | ||
}, | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "number" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "number" | ||
} | ||
], | ||
"minItems": 2, | ||
"type": "array" | ||
}, | ||
"MyTupleWithRest": { | ||
"additionalItems": { | ||
"title": "third", | ||
"type": "string" | ||
}, | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "string" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "number" | ||
} | ||
], | ||
"minItems": 2, | ||
"type": "array" | ||
}, | ||
"MyNestedArrayWithinTuple": { | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "string" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "number" | ||
}, | ||
{ | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "third", | ||
"type": "array" | ||
} | ||
], | ||
"maxItems": 3, | ||
"minItems": 3, | ||
"type": "array" | ||
}, | ||
"MyNestedArrayWithinTupleWithRest": { | ||
"additionalItems": { | ||
"title": "third", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"type": "array" | ||
}, | ||
"items": [ | ||
{ | ||
"title": "first", | ||
"type": "string" | ||
}, | ||
{ | ||
"title": "second", | ||
"type": "number" | ||
} | ||
], | ||
"minItems": 2, | ||
"type": "array" | ||
} | ||
} | ||
} |