Skip to content

Parameterizes CustomEvent and CustomEventInit #304

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

Conversation

Todberg
Copy link

@Todberg Todberg commented Oct 6, 2017

In relation to the open issue, microsoft/TypeScript#14785.
This guy @arjunyel creates a commit, but this never makes it to a PR. So here it is!

NOTE that I was not able to run the tests sucessfully when I ran build.cmd.

…ventInit interfaces

refactor: adds readonly to CustomEventInit detail property

refactor: adds default argument to CustomEventInit
@arjunyel
Copy link
Contributor

arjunyel commented Oct 6, 2017

Thank you for finishing it!

@Todberg
Copy link
Author

Todberg commented Oct 6, 2017

No problem! Do you know why the tests are failing? I followed the instructions in the readme..

@arjunyel
Copy link
Contributor

arjunyel commented Oct 6, 2017

You have to add the type information to inputfiles/addedTypes.json or inputfiles/overridingTypes.json I'm not sure which for this pull request, that's why I didn't submit it :D

You need to add the typing information to the JSON and then change the file in baselines/dom.generated.d.ts

When you run the build.cmd it creates the file in generated/dom.generated.d.ts using the info in the json files, then it compares it to what you manually created in the baselines folder. That test needs to pass in order for the change to be successful.

Here's an example of one of my pull requests https://github.com/Microsoft/TSJS-lib-generator/pull/282/files

@Todberg
Copy link
Author

Todberg commented Oct 6, 2017

Thanks for the explaination. I manged to figure out how to override the properties and methods, however, I'm having difficulties figuring out how to override optional properties and interfaces.

Optional Properties

Changes to CustomEventInit in baselines/dom.generated.d.ts:

interface CustomEventInit extends EventInit {
    readonly detail?: T;
}

Changes to overridingTypes.json:

{
  "kind": "property",
  "interface": "CustomEventInit",
  "readonly": true,
  "name": "detail",
  "type": "T"
}

I suspect that it doesn't work because of the optional ? in the baseline file! How can I state that in the json?

Interfaces

Changes to CustomEventInit in baselines/dom.generated.d.ts:

interface CustomEventInit<T = any> extends EventInit {
    readonly detail?: T;
}

Changes to overridingTypes.json:

{
  "kind": "interface",
  "interface": "CustomEventInit",
  "name": "CustomEventInit<T = any>"
 }

For this have no idea to what could be wrong? I have looked through some of the merged pull-requests, however, there are no examples of this.

@Todberg Todberg closed this Oct 6, 2017
@Todberg Todberg reopened this Oct 6, 2017
@jthoms1
Copy link
Contributor

jthoms1 commented Nov 2, 2017

I wanted this same change, so started doing some research and trying to read the f sharp code. It appears that there is no way to accomplish this in the compiler. I am able to add new interfaces, but the code to modify or remove interfaces does not exist.

Is there another route that should be taken or is a PR needed to update the TS.fsx file? @mhegazy

@mhegazy
Copy link
Contributor

mhegazy commented Nov 2, 2017

For adding the generic type parameter, we will need a new property in overridingTypes.json, call it typeParameter to be added, and then pick that up and write in ts.fsx while we are doing the transformation.

@jthoms1
Copy link
Contributor

jthoms1 commented Nov 3, 2017

I will make a PR to allow for overridingTypes with typeParameter to work in the ts.fsx file.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 6, 2018

The format of the input files has changed a bit since this PR was opened. closing for now, please reopen after merging with master.

@mhegazy mhegazy closed this Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants