Skip to content
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

Typescript type #3094

Closed
wants to merge 1 commit into from
Closed

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Oct 4, 2016

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

If this PR contains a breaking change, please describe the following...

  • Impact:
  • Migration path for existing applications:
  • Github Issue(s) this is regarding:

Other information:
This resolves issue #3045.

@marvinhagemeister
Copy link

Great work! Out of curiosity, since I'm new to typescript: How do you run the tests? Is a simple compile enough?

@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 4, 2016

@marvinhagemeister You can read more about here. You run test with a simple compile. It there are no errors like this

loader-test.ts(9,9): error TS2322: Type '{ entry: { alpha: string; beta: string; }; module: { loade1rs: { test: RegExp; loader: string; }[...' is not assignable to type 'Webpack'.
  Types of property 'module' are incompatible.
    Type '{ loade1rs: { test: RegExp; loader: string; }[]; }' is not assignable to type 'Module'.
      Object literal may only specify known properties, and 'loade1rs' does not exist in type 'Module'.

then definition is ok 😄

@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 4, 2016

@TheLarkInn @sokra can you please check out TODO's in the code and tell me what to insert there.

@@ -0,0 +1,19 @@
/// <reference path="webpack.d.ts" />
Copy link
Contributor

@quantizor quantizor Oct 4, 2016

Choose a reason for hiding this comment

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

aggressive (typo in the file name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from 045a284 to 386fe25 Compare October 4, 2016 18:46
@TheLarkInn
Copy link
Member

@gajus can you also assist here.

/*
Set the value of `require.amd` and `define.amd`.
*/
amd?: any; // TODO missing type
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Might change the comment on properties to JSDoc style. This enable better tooltip in editor. For exmaple
/**
 *Set the value of `require.amd` and `define.amd`.
 */

Copy link
Contributor Author

@NejcZdovc NejcZdovc Oct 5, 2016

Choose a reason for hiding this comment

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

Good suggestion, changed.

/*
Set the value of `require.amd` and `define.amd`.
*/
amd?: any; // TODO missing type
Copy link
Contributor

Choose a reason for hiding this comment

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

amd?: "require.amd" | "define.amd";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zhaoshengjun I am not so sure about these two strings anymore. If you checkout documentation you can see there is an object example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheLarkInn can you please clarify this property. Should be string literal here or object of some kind?

Copy link
Member

@TheLarkInn TheLarkInn Oct 12, 2016

Choose a reason for hiding this comment

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

Starting tracing the use of the config value from here: https://github.com/webpack/webpack/blob/master/lib/WebpackOptionsApply.js#L248

To:
https://github.com/webpack/webpack/blob/master/lib/dependencies/AMDPlugin.js#L92-L100

It appears that the default is an empty Object, and that it is {[key: string]: boolean} if values are added. The key seems to represent the npm module/library name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

onlyModule?: boolean;
}

type EntryItem = string | string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

If the type is only used in one place, I would suggest to do them inline. It's also for better editor tooltips.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not used only in one placed, that's why I added it to type.

entry: WebpackType.EntryItem | {[key: string]: WebpackType.EntryItem};

Copy link
Contributor

Choose a reason for hiding this comment

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

My fault, pointed to the wrong line.

I mean for OutputLibraryTarget , Stats and Target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I prefer to have this long list of enums in separate variable, so it's a lot more readable for me.

Boolean: You can pass `false` to disable it.
Object: You can pass an object to enable it and let webpack use the passed object as cache.This way you can share the cache object between multiple compiler calls.
*/
cache?: (boolean | Object);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to add an Object interface. Reason is the current definition will let cache = "true" pass, which should not.

interface Object {
[key: string]: any;
}

After adding this, the above statement will cause error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct. Fixed

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from 386fe25 to ebf2008 Compare October 5, 2016 03:38
@zhaoshengjun
Copy link
Contributor

Awesome work!

@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 6, 2016

I finished with this task, so I am just waiting for you guys to fill out the blanks (where is TODO) and check if everything is in order. I will remove WIP tag from the title.

@NejcZdovc NejcZdovc changed the title WIP: Typescript type Typescript type Oct 6, 2016
__filename?: boolean | "mock";
console?: boolean;
global?: boolean;
process?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Buffer, console and process can also be "mock" or "empty".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In scheme.json which is a base line for this PR it's says only boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fixed now.

libraryTarget?: OutputLibraryTarget;

// The output directory as **absolute path** (required).
path?: string;
Copy link
Member

Choose a reason for hiding this comment

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

If it is required, it should not have a ?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct, but in the tests that you can find in this repository, there is a lot of example without path in output object, so I am not so sure about it. But on website it's required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now let's say it's required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheLarkInn Please clarify this, because I see a lot of examples where path is not in configuration of output, but in documentation it says to be required.

root?: string;
}

interface OutputDevtoolLineToLine {
Copy link
Member

@Jessidhia Jessidhia Oct 6, 2016

Choose a reason for hiding this comment

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

Would be nice if this (and everything else using test/include/exclude) would work like a RuleSetConditionObject, but that's outside this scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what you mean by that

Copy link
Member

Choose a reason for hiding this comment

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

They both have include, exclude and test keys, but they don't necessarily seem to work the same. Would be nice if both the implementation and the object format were the same.

| "node"
| "async-node"
| "node-webkit"
| "electron";
Copy link
Member

Choose a reason for hiding this comment

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

"atom" / "electron-main" are (possibly?) aliases to "electron". There is also a separate "electron-renderer" target.

Copy link
Contributor Author

@NejcZdovc NejcZdovc Oct 6, 2016

Choose a reason for hiding this comment

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

As described here there are only these. Same is defined in the scheme.json.

Copy link
Member

@Jessidhia Jessidhia Oct 6, 2016

Choose a reason for hiding this comment

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

I checked the source code itself; looks like an omission in the docs and scheme.json.

Copy link
Member

Choose a reason for hiding this comment

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

Let's create an issue for this for the JSON Schema so that once we fix it there, we fix it in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do and create PR for schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created PR for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and added to the definition.

* A developer tool to enhance debugging.
* Note: Boolean can be used only with value `false`.
*/
devtool?: string | boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Would string | false work, or are constants in types only allowed for strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly no.

Copy link
Member

@TheLarkInn TheLarkInn Oct 6, 2016

Choose a reason for hiding this comment

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

@mhegazy @DanielRosenwasser is there a better solution for this that you can think of?

Choose a reason for hiding this comment

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

string | false should be possible in TS 2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @DanielRosenwasser for update, I was relaying to much on IDE-a for checking correction of definition. Added.

@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 6, 2016

@sokra In documentation there is <node buildin>: true, "mock", "empty" or false. Is this something that can be a single value for node property instead of object with options?

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from ebf2008 to c082fd7 Compare October 6, 2016 06:05
@TheLarkInn
Copy link
Member

@sokra In documentation there is : true, "mock", "empty" or false. Is this something that can be a single value for node property instead of object with options?

I would say we conform exactly with the JSON Validation Schema. If we need to change this, we'll need to change it in both places. I want to keep these things in sync as much as possible.

@ianks
Copy link
Contributor

ianks commented Oct 7, 2016

Can these typings be added to the package.json?

@TheLarkInn
Copy link
Member

@ianks yes definitely. @NejcZdovc @zhaoshengjun add a new field called "typings": and specify the path to that typings file.

Here's an example PR of someone doing it. jeffbcross/angularfire2@b3a5a3a

@NejcZdovc
Copy link
Contributor Author

@TheLarkInn first I wanted to confirm location of definition file before adding it into package.json. So is the location correct or should we move it?

@TheLarkInn
Copy link
Member

@DanielRosenwasser is there any general recommendation in placement for type definitions files in a package, that would contradict where we are creating it now in this PR.

@DanielRosenwasser
Copy link

DanielRosenwasser commented Oct 7, 2016

In my opinion, the "schema" type should just be exposed as part of the webpack library .d.ts files, so that users can write something like

import webpack = require("webpack");

let config: webpack.WebpackConfiguration = {
   // ...
};

export = config;

@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 8, 2016

@DanielRosenwasser I am curious why not add it to DT, import it as @type/webpack and add it to the package.json as typings. Then use it as let config: Webpack = {.

AFAIK this is the only .d.ts file that is part of webpack library. @TheLarkInn will there be more .d.ts files for example for plugins?

@NejcZdovc NejcZdovc mentioned this pull request Oct 9, 2016
11 tasks
@TheLarkInn
Copy link
Member

I think overall in the future if we transition this project to Typescript then each plugin technically will have a type. But for now we do not. I don't know if that answers the question for you.

@TheLarkInn
Copy link
Member

#3112 had been merged so you can update accordingly

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch 2 times, most recently from 1a6a4e7 to 57ac4e0 Compare October 12, 2016 04:26
@NejcZdovc
Copy link
Contributor Author

Updated accordingly of the #3112

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from 57ac4e0 to 4e700c8 Compare October 12, 2016 04:39
stats?: WebpackType.Object | boolean | WebpackType.Stats;

/**
* TODO add description
Copy link
Member

@TheLarkInn TheLarkInn Oct 12, 2016

Choose a reason for hiding this comment

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

You could use something like this. I don't have good wording ideas for the second sentence, but essentially trying to capture what happens here

Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target. Can also expose extra global variables into the webpack module scope (required for specific targets (IE: electron))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target. Can also use predefined bootstrap functions based on targets such as electron, atom, etc.

What about something like that?

Copy link
Member

Choose a reason for hiding this comment

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

They are all predefined. So maybe that part is unnecessary (unless I'm misunderstanding).

I think:

Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target.

Should be fine.

Copy link
Contributor Author

@NejcZdovc NejcZdovc Oct 12, 2016

Choose a reason for hiding this comment

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

As far as I understand this is that you can specify string (predefined function as electron) or you can specify completely custom function, which is called here.

That's why we have: target?: Function | WebpackType.Target;

This is the reason why I formatted my sentence like this.

@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from 4e700c8 to f173a83 Compare October 13, 2016 04:54
@NejcZdovc NejcZdovc force-pushed the pr/#3045-definition branch from f173a83 to 04953b6 Compare October 13, 2016 07:12
@NejcZdovc
Copy link
Contributor Author

NejcZdovc commented Oct 16, 2016

Ok, so AFAIK this is blocking merge of this PR

  • Position of this d.ts file
  • How will we use TS in reality (for now we have two proposals)

How can I help to resolve this two, so I can close this and go to another issue? @TheLarkInn @DanielRosenwasser

type RuleSetRules = RuleSetRule[];
}

interface Webpack {
Copy link
Contributor

Choose a reason for hiding this comment

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

This interface should be exported, no? Doesn't make much sense having a type definition otherwise.

@SimenB
Copy link
Contributor

SimenB commented Dec 24, 2016

Any plans to add matching flow type definitions?

EDIT: Saw the linked issue, but will there be any process to keep them in sync in the future? If TS is a part of this repo, but flow is not.

@webpack-bot
Copy link
Contributor

@NejcZdovc The most important CI builds failed. This way your PR can't be merged.

Please take a look at the CI results from travis (error) and appveyor (failure) and fix these issues.

@sokra
Copy link
Member

sokra commented Jan 2, 2018

old, controversal, there is typing in DT, closing

@sokra sokra closed this Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.