-
Notifications
You must be signed in to change notification settings - Fork 325
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
Feature/methods #121
Closed
Closed
Feature/methods #121
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f10047a
:construction: Start rudimentary method-support
36d2437
:construction: Add basic type-arguments and returntype
07eeb2d
:sparkles: Make function be upper case
7a71862
:rotating_light: add Test for method
cb6f765
:fire: Reset files, that shouldn't have been commited back to master
5920297
:muscle: creating worst-case test-scenario
3a5e509
:construction: Improve method-tests
5b0929f
:package: cleanup code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@ | ||
interface MyObject { | ||
setTime?<T extends Array<string> & {name: {first: string, last: string}}, T2>(d: {name: string, test: number} | {name: {first: string, last: string}}, someParam?: T2): Array<T>; | ||
} |
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,93 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"setTime": { | ||
"parameters": [ | ||
{ | ||
"name": "d", | ||
"type": "union", | ||
"typeArguments": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"test": { | ||
"type": "number" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "object", | ||
"properties": { | ||
"first": { | ||
"type": "string" | ||
}, | ||
"last": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "someParam", | ||
"optional": true, | ||
"type": "T2" | ||
} | ||
], | ||
"typeParameters": [ | ||
{ | ||
"name": "T", | ||
"constraint": { | ||
"type": "intersection", | ||
"typeArguments": [ | ||
{ | ||
"type": "Array", | ||
"typeArguments": [ | ||
{ | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "object", | ||
"properties": { | ||
"first": { | ||
"type": "string" | ||
}, | ||
"last": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "T2" | ||
} | ||
], | ||
"type": "object", | ||
"returnType": "Array", | ||
"returnTypeArguments": [ | ||
{ | ||
"type": "T" | ||
} | ||
], | ||
"optional": true | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-04/schema#" | ||
} |
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,3 @@ | ||
interface MyObject { | ||
setTime(d: string): void; | ||
} |
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,18 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"setTime": { | ||
"parameters": [ | ||
{ | ||
"name": "d", | ||
"type": "string" | ||
} | ||
], | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"setTime" | ||
], | ||
"$schema": "http://json-schema.org/draft-04/schema#" | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this syntax. Can you send me some resources so I can evaluate this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domoritz: TypeScript - generics
string
inArray<string>
is atypeArgument
implements
inT implements Array<string>
makesArray<string>
aconstraint
(onT
)union
-types andintersection
-types in method-definitions i usedtypeArguments
to represent the types that are part of that union/intersection.I unfortunately don't really have sources on how a function should be represented in a JSON-Schema, because there barely are sources. I've read somewhere that JSON-Schema isn't really meant to include functions, so i somewhat came up with my own way to represent them.
If there happens to be standards for this, that i just overlooked, i'm more than happy to follow it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know Generics in typescript but this syntax in JSON schema strikes me as an odd use case for JSON schema. A schema is usually intended for data structures and not really for functions or method signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, usually you wouldn't use JSON-Schema for that, because a function has functionality. But the use case here is not to verify a whole function (including the implementation), but to verify it's declaration. The goal is to compare "functions" based on their name, parameter, parameter-order, parameter-types, return-type etc.
I think JSON-Schema can be a good tool to verify function-declarations, without comparing the function-implementation.