Skip to content

Add overrides for interface types and add CustomEvent types for testing. #319

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

Merged
merged 4 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions TS.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module InputJson =
| SignatureOverload
| TypeDef
| Extends
| TypedInterface
override x.ToString() =
match x with
| Property _ -> "property"
Expand All @@ -172,6 +173,7 @@ module InputJson =
| SignatureOverload _ -> "signatureoverload"
| TypeDef _ -> "typedef"
| Extends _ -> "extends"
| TypedInterface _ -> "typedinterface"

let getItemByName (allItems: InputJsonType.Root []) (itemName: string) (kind: ItemKind) otherFilter =
let filter (item: InputJsonType.Root) =
Expand Down Expand Up @@ -779,6 +781,10 @@ module Emit =
(DomTypeToNullableTsType m.Type m.Nullable.IsSome) = expectedMType &&
m.Params.Length = 1 &&
(DomTypeToTsType m.Params.[0].Type) = expectedParamType
let processInterfaceType iName =
match getOverriddenItems ItemKind.TypedInterface Flavor.All |> Array.tryFind (matchInterface iName) with
| Some it -> iName + "<" + (it.Parameters |> String.concat ", ") + ">"
| _ -> iName

/// Emit overloads for the createElement method
let EmitCreateElementOverloads (m: Browser.Method) =
Expand Down Expand Up @@ -1160,9 +1166,9 @@ module Emit =

let processedIName = processIName i.Name
if processedIName <> i.Name then
Pt.PrintlToStack "interface %s extends %s {" i.Name processedIName
Pt.PrintlToStack "interface %s extends %s {" (processInterfaceType i.Name) processedIName

Pt.Printl "interface %s" processedIName
Pt.Printl "interface %s" (processInterfaceType processedIName)
let finalExtends =
let overridenExtendsFromJson =
InputJson.getOverriddenItemsByInterfaceName ItemKind.Extends Flavor.All i.Name
Expand Down Expand Up @@ -1387,10 +1393,11 @@ module Emit =
EmitConstructor flavor i

let EmitDictionaries flavor =

let emitDictionary (dict:Browser.Dictionary) =
match dict.Extends with
| "Object" -> Pt.Printl "interface %s {" dict.Name
| _ -> Pt.Printl "interface %s extends %s {" dict.Name dict.Extends
| "Object" -> Pt.Printl "interface %s {" (processInterfaceType dict.Name)
| _ -> Pt.Printl "interface %s extends %s {" (processInterfaceType dict.Name) dict.Extends

let emitJsonProperty (p: InputJsonType.Root) =
let readOnlyModifier =
Expand Down
10 changes: 5 additions & 5 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ interface ConstrainVideoFacingModeParameters {
ideal?: VideoFacingModeEnum | VideoFacingModeEnum[];
}

interface CustomEventInit extends EventInit {
detail?: any;
interface CustomEventInit<T = any> extends EventInit {
detail: T;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detail should still be optional? or is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good otherwise. thanks!

}

interface DeviceAccelerationDict {
Expand Down Expand Up @@ -2374,9 +2374,9 @@ declare var CSSSupportsRule: {
new(): CSSSupportsRule;
};

interface CustomEvent extends Event {
readonly detail: any;
initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: any): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name of the method is missing.

interface CustomEvent<T = any> extends Event {
readonly detail: T;
(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void;
}

declare var CustomEvent: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to change this one too, this is your entry point to an event.. it should be:

declare var CustomEvent: {
prototype: CustomEvent;
     new<T>(typeArg: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>;
 };

Expand Down
35 changes: 35 additions & 0 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
[
{
"kind": "typedinterface",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not think you need a new kind here.. just add a property typeParameters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would kind be interface and then parameters would become typeParameters?

"interface": "CustomEventInit",
"parameters": [
"T = any"
]
},
{
"kind": "property",
"interface": "CustomEventInit",
"name": "detail",
"type": "T"
},
{
"kind": "typedinterface",
"interface": "CustomEvent",
"parameters": [
"T = any"
]
},
{
"kind": "property",
"interface": "CustomEvent",
"readonly": true,
"name": "detail",
"type": "T"
},
{
"kind": "method",
"interface": "CustomEvent",
"name": "initCustomEvent",
"signatures": [
"(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to include the name here. i.e. initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T)

]
},
{
"kind": "constructor",
"interface": "Response",
Expand Down
7 changes: 7 additions & 0 deletions inputfiles/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@
"baseInterface": "ParentNode",
"interface": "Document"
},
{
"kind": "typedinterface",
"interface": "CustomEventInit",
"parameters": [
"T = any"
]
},
{
"kind": "interface",
"name": "ParentNode",
Expand Down