Skip to content

Commit

Permalink
Prepare for initial 0.8.x release
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost91- committed Jul 7, 2021
1 parent 22688f7 commit 018973e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 47 deletions.
70 changes: 34 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We also recommend to take a look at the corresponding project board to make sure

#### Branching model

We use a very simple branching model. We have a branch for every supported Foundry VTT version called `foundry-<major>.<minor>.x` (e.g. `foundry-0.7.x`). All changes for the type definitions for a given Foundry VTT version need to be made through Pull Requests towards the corresponding branch.
We use a very simple branching model. We have a branch for every supported Foundry VTT version called `foundry-<major>.<minor>.x` (e.g. `foundry-0.8.x`). All changes for the type definitions for a given Foundry VTT version need to be made through Pull Requests towards the corresponding branch.

#### Submitting pull requests

Expand All @@ -70,12 +70,13 @@ In very rare occasions, it is acceptable to disable prettier for a specific part

### General Guidelines

1. Try to match the source code of `foundry.js` (and other modules from 0.8.0 onwards) as closely as possible in your type definitions. In particular, the order of declarations should be exactly the same. This allows for easy side by side viewing of `foundry.js` and the type definitions, making the life of code reviewers much easier :)
2. Try not to pollute the global namespace with custom types that are not declared by foundry itself (typedefs from `foundry.js` should be declared). Instead use a namespace named like the related class and put your custom type in there.
3. Every class has its own file. The files are structured by class hierarchy. Declarations for code that is not a class belongs directly in the `foundry` folder. For 0.8.x and up, we are still figuring out how to structure things with respect to the namespaces / modules that are introduced.
4. Utility types not defined in foundry belong in `types/utils.d.ts`
5. Augments for libraries bundled with Foundry VTT belong in their corresponding file in `types/augments`.
6. Write tests where applicable. Not everything needs to be tested, these are just type definitions after all. But in particular for complicated type definitions it makes a lot of sense to add tests. That way you can also verify for yourself that your type definitions are actually working as intended.
1. Try to match the source code Foundry VTT as closely as possible in your type definitions. In particular, the order of declarations should be exactly the same. This allows for easy side by side viewing of the original source code and the type definitions, making the life of code reviewers much easier :)
2. Try not to pollute the global namespace with custom types that are not declared by Foundry VTT itself (typedefs from from Foundry VTT should be declared). Instead use a namespace named like the related class and put your custom type in there. Alternatively, if you don't want the type to be easily accessible at all, make your declaration file a a module (e.g. by adding an empty export), declare the things should should be visible globally in a `declare global {}` block and simply put the things that should _not_ be visible globally outside of that block.
3. The file structure follows the structure of Foundry VTT but additionally, every class has its own file and the files are structured by class hierarchy. Declarations for code that is not a class should be structured in a sensible way but there are no clear guidelines.
4. Generic utility types not defined in Foundry VTT belong in `src/types/utils.d.ts`.
5. Utility types that are specific to Foundry VTT belong in `src/types/helperTypes.d.ts`.
6. Augments for libraries bundled with Foundry VTT belong in their corresponding file in `src/types/augments`.
7. Write tests where applicable. Not everything needs to be tested, these are just type definitions after all. But in particular for complicated type definitions it makes a lot of sense to add tests. That way you can also verify for yourself that your type definitions are actually working as intended.

### Common Patterns

Expand All @@ -91,63 +92,60 @@ Example:

```typescript
declare class ActorSheet<
D extends object = ActorSheet.Data<Actor>,
O extends Actor = D extends ActorSheet.Data<infer T> ? T : Actor
> extends DocumentSheet<D, O> {
/* ... */

Options extends ActorSheet.Options = ActorSheet.Options,
Data extends object = ActorSheet.Data<Options>
> extends DocumentSheet<Options, Data, InstanceType<ConfiguredDocumentClass<typeof Actor>>> {
/**
* @override
* @defaultValue
* ```typescript
* mergeObject(super.defaultOptions, {
* foundry.utils.mergeObject(super.defaultOptions, {
* height: 720,
* width: 800,
* template: "templates/sheets/actor-sheet.html",
* template: 'templates/sheets/actor-sheet.html',
* closeOnSubmit: false,
* submitOnClose: true,
* submitOnChange: true,
* resizable: true,
* baseApplication: "ActorSheet",
* dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
* })
* baseApplication: 'ActorSheet',
* dragDrop: [{ dragSelector: '.item-list .item', dropSelector: null }],
* token: null,
* });
* ```
*/
static get defaultOptions(): DocumentSheet.Options;

static get defaultOptions(): ActorSheet.Options;
/* ... */
}
```

#### Type for a class being used as a value (e.g. assigned to a variable)

The type should most likely be `ConstructorOf<NameOfTheClass>`. This will also allow deriving classes to be used as value. In rare occasions (i.e. when really only instances of this specific class may be assigned, no deriving classes), `typeof NameOfTheClass` can be used.
If the type is not configurable by the user, it should most likely be `ConstructorOf<NameOfTheClass>`. This will also allow deriving classes to be used as value. In rare occasions (i.e. when really only instances of this specific class may be assigned, no deriving classes), `typeof NameOfTheClass` can be used.

Example:
Example (`documentClass` is configurable, `sheetClass` is not):
```typescript
/**
* Configuration for the ActiveEffect embedded Entity
*/
ActiveEffect: {
/**
* @defaultValue `ActiveEffect`
* Configuration for the ActiveEffect embedded document type
*/
entityClass: ConstructorOf<ActiveEffect>;

/**
* @defaultValue `ActiveEffectConfig`
*/
sheetClass: ConstructorOf<ActiveEffectConfig>;
};
ActiveEffect: {
/**
* @defaultValue `ActiveEffect`
*/
documentClass: ConfiguredDocumentClassOrDefault<typeof ActiveEffect>;

/**
* @defaultValue `ActiveEffectConfig`
*/
sheetClass: ConstructorOf<ActiveEffectConfig>;
};
```

#### A property in `SCREAMING_SNAKE_CASE` is being assigned to a class after its definition in `foundry.js`
#### A property in `SCREAMING_SNAKE_CASE` is being assigned to a class after its definition in Foundry VTT

This is just a static property of the class. Add it to the class at the very bottom.

Example:

In `foundry.js`
In Foundry VTT
```javascript
class AVSettings {
/* ... */
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ TypeScript type definitions for [Foundry Virtual Tabletop](https://foundryvtt.co

We aim to support the latest patch release of minor versions of Foundry VTT, starting with 0.7.

At the moment, only 0.7.10 is supported. Work on 0.8.x is in progress but there is still a lot to be done.

At the moment, the latest 0.7.x and 0.8.x versions are supported. However, note that work on 0.8.x has not been completed yet, so there are still quite a few things which are either missing or typed incorrectly. Take a look at [0.8.x issues](https://github.com/League-of-Foundry-Developers/foundry-vtt-types/issues?q=is%3Aopen+is%3Aissue+label%3A%22foundry+0.8.x%22) to see what still needs to be done.
## Installation

You can install foundry-vtt-types from the [npm registry](https://npmjs.org/). We provide distribution tags for the different supported Foundry VTT versions that have the form `fvtt-<foundry-version>`. For example, the distribution tag for Foundry VTT 0.7.10 is `fvtt-0.7.10`.
You can install foundry-vtt-types from the [npm registry](https://npmjs.org/). We provide distribution tags for the different supported Foundry VTT versions that have the form `fvtt-<foundry-version>`. For example, the distribution tag for Foundry VTT 0.8.8 is `fvtt-0.8.8`.

In order to install the desired version, run

```sh
npm install --save-dev @league-of-foundry-developers/foundry-vtt-types@fvtt-<foundry-version>
```

For example, to install the type definitions for Foundry VTT 0.7.10 run
For example, to install the type definitions for Foundry VTT 0.8.8 run

```sh
npm install --save-dev @league-of-foundry-developers/foundry-vtt-types@fvtt-0.7.10
npm install --save-dev @league-of-foundry-developers/foundry-vtt-types@fvtt-0.8.8
```

You can then update foundry-vtt-types using the regular update mechanism for npm (see [npm update](https://docs.npmjs.com/cli/v7/commands/npm-update)).
Expand All @@ -46,7 +45,8 @@ Add foundry-vtt-types to your types section in your `tsconfig.json`:
{
"compilerOptions": {
"types": ["@league-of-foundry-developers/foundry-vtt-types"],
"moduleResolution": "node"
"moduleResolution": "node",
"strictNullChecks": true,
}
}
```
Expand All @@ -55,8 +55,9 @@ This will make the type definitions available globally in your project.

Make sure you are using `"moduleResolution": "node"`, too. It is required for some dependencies to be resolved correctly.

You can find some information about how to actually work with the type definitions in the [Wiki](https://github.com/League-of-Foundry-Developers/foundry-vtt-types/wiki). For example, [[0.7.x] Actors and Items](https://github.com/League-of-Foundry-Developers/foundry-vtt-types/wiki/%5B0.7.x%5D-Actors-and-Items) describes how to set up custom `Actor` and `Item` classes for 0.7.x using the types.
Also make sure to set `"strictNullChecks": true` because otherwise, some of the conditional types used in the type definitions resolve incorrectly and you will see a lot of errors.

You can find some information about how to actually work with the type definitions in the [Wiki](https://github.com/League-of-Foundry-Developers/foundry-vtt-types/wiki). If you are working with Foundry VTT 0.8.x, a good starting point is [[0.8.x] FAQ](https://github.com/League-of-Foundry-Developers/foundry-vtt-types/wiki/%5B0.8.x%5D-FAQ).

## Acknowledgments

Expand All @@ -66,7 +67,7 @@ Originally forked from [Foundry Project Creator Types](https://gitlab.com/foundr

Contributions are very welcome in order to decrease the individual workload. Filing issues for wrong / missing types is also a great way to help us improve the type definitions.

There are individual branches for the different supported Foundry VTT versions that are being worked on. They are named according to the minor version of the Foundry VTT version, e.g. the branch for Foundry VTT 0.7 is called `foundry-0.7.x`. All work to improve the type definitions for a specific version needs to be done through Pull Requests to the corresponding branch.
There are individual branches for the different supported Foundry VTT versions that are being worked on. They are named according to the minor version of the Foundry VTT version, e.g. the branch for Foundry VTT 0.8 is called `foundry-0.8.x`. All work to improve the type definitions for a specific version needs to be done through Pull Requests to the corresponding branch.

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for more details on how to contribute.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@league-of-foundry-developers/foundry-vtt-types",
"version": "0.7.9-6",
"version": "0.8.8-0",
"description": "TypeScript type definitions for Foundry VTT",
"scripts": {
"lint": "tsc && eslint --ext .d.ts,.test-d.ts .",
Expand Down

0 comments on commit 018973e

Please sign in to comment.