* [Enhancements]: strictNullCheck and filtering:
* (d3-selection) [Enhancement]: Validated, updated and activated to enforece `strictNullChecks`. `BaseType` updated to include `null`. As a result of this approach, the developer must explicitly include `| null`, if a Selection or a (sub-)selecting method may contain `null` element(s). By the same token, the `node()` method, will return `null` only, if the Selection to which it was applied may contain `null` element(s).
* (d3-selection) [Enhancement]: Added additional signature to `filter(...)` method such that a generic can be used to control the type of the filtered elements, should they be a subset of the unfiltered types.
* (d3-selection) [Enhancement]: Added `Document` to `BaseType` union type.
* (d3-transition) [Enhancement]: Validated, updated and activated to enforece `strictNullChecks`. `BaseType` updated to include `null`. As a result of this approach, the developer must explicitly include `| null`, if a Transition or a (sub-)selecting method may contain `null` element(s). By the same token, the `node()` method, will return `null` only, if the Transition to which it was applied may contain `null` element(s).
* (d3-transition) [Enhancement]: Added additional signature to `filter(...)` method such that a generic can be used to control the type of the filtered elements, should they be a subset of the unfiltered types.
* (d3-selection-multi) [Enhancement]: updated `ValueMap` type use extension of selection/transition `BaseType` as defined above consistent with `strictNullChecks`.
* (d3-selection-multi) [Test Fix]: Updated tests where a Value Function is used to return a ValueMap for each selected item, as the ValueMap must be defined as a mapping object idiomatically, the test was changed to never return `null` as a result of the value function. Instead it returns `{}`, when no updates are required for the currently iterated selected element.
* In general, for all three above modules: Tests have been updated to be more explicit about type-checking inside callback functions. Also, where shortcuts where taken in the shape tests to simply test interface/signature contracts, without necessary variable initialization, mock initializations have been included. This is necessitated by enabling `strictNullChecks`.
* d3-force
* (d3-force) [Enhancement]: Validated, updated and activated to allow for `strictNullChecks`. When using `force(name)` getter on `Simulation`, it is now up to the developer to use the right generic narrowing to exclude `undefined` as a return type, if it is known with certainty that the retrieved force has prevsiously been defined. By default, it may be `undefined` as is the standard API specification.
* (d3-force) [Fix]: The initialize method has been added explicitly to the predefined forces `ForceCollide`, `ForceCenter`, `ForceLink`, `ForceManyBody`, `ForceX` and `ForceY`. This conforms to the implementation of these forces, where it is implemented. Inhertitance from the generic `Force` inaccurately let it appear optional.
* (d3-force) [Chore] Tests added/updated and some linting.
* d3-force ForceLink JSDoc update:
* (d3-force) [Chore] Update JSDoc comment for `id(...)` accessor on `ForceLink`. This is related to the corresponding wording change in the API documentation in follow-up to the changes made to d3-force issue 72.
* d3-zoom strictNullChecks
* (d3-zoom) [Enhancement] Validated, updated and activated for use with `strictNullChecks`. Tests updated.
* d3-brush strictNullChecks
* (d3-brush) [Enhancement] Validate, update and activate for use with `strictNullChecks`. Tests updated.
* d3-drag strictNullChecks
* (d3-drag) [Enhancement]: Validate, update and activate for use with strictNullChecks.
* (d3-zoom) to v1.1.0
* (d3-zoom) [Feature]: Adds suppport for `zoom.interpolate(...)`. Tests added
* (d3-zoom) [Chore]: Updated JSDoc comment for `zoomTransform(...)`
* (d3-transition) JSDoc comment
* (d3-transition) [Chore] Updated JSDoc comment on `selection.transition(...)`
* (d3-transition) [Chore] bumped version to 1.0.3 to indicate up to which module version the definitions were reviewed
* Bump patch versions of underlying modules
* (d3-brush) (d3-drag) (d3-force) [Chore]: To indicate up to which patch version the files definitions were validated, patch version number has been bumped
* TS Lint and Minor Changes:
* (d3-brush) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-drag) [Chore]: Added tslint.json to disable "unified-signatures" rule. Linted tests.
* (d3-force) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-force) [Chore]: Completed linting.
* (d3-selection) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-selection) [Fix]: Changed `CustomEventParameters` and `NamespaceLocalObject` and `NamespaceMap` to be interfaces as opposed to types.
* (d3-selection) [Chore]: Completed linting of defintion and tests,
* (d3-selection-multi) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-selection-multi) [Chore]: Completed linting of definition and tests. Used `// tslint:disable-next-line:interface-over-type-literal` for type alias ValueMap. Using type is better here for IDE hints, as the hint replaces alias with its content. This saves separate "peeking" as would be the case for interface. Also, there is no need to extend the type. For the entire test file `// tslint:disable:object-literal-shorthand` was applied, as the object literals actually need to use functions and not arrow function "short hand" ("this" context will be bound rather than lexically scoped)
* (d3-selection-multi) [Chore]: Minor JSDoc comment additions for completeness.
* (d3-transition) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-transition) [Chore]: Minor JSDoc comment additions for completeness.
* (d3-transition) [Chore]: Completed linting.
* (d3-zoom) [Chore]: Added tslint.json to disable "unified-signatures" rule
* (d3-zoom) [Chore]: Completed linting.
* strictNullChecks
* (d3-selection) [Fix]: Re-inserted `| null` into return type of `node()`. Fixed all tests, for mock-purposes using `!` post-fix where necessary. Note, this includes using post-fix on document.querySelector(...) which now also includes possible `null` return type.
* (d3-transition) [Fix]: Re-inserted `| null` into return type of `node()`. Fixed all tests, for mock-purposes using `!` post-fix where necessary. Note, this includes using post-fix on document.querySelector(...) which now also includes possible `null` return type.
* (d3-force) [Fix]: Moved return type of `force('forcename')` getter to include `| undefined` unconditionally. This is a change from allowing the casting using the generic to exclude `undefined`. This change was made for consistency with the treatment of e.g. `node()` (see above)
* (d3-drag) [Chore]: Adjust test to mock-assert non-null using `!` when using `node()`
* d3-zoom fix test
* (d3-zoom) [Chore] Needed to assert non-null node() return-type for testing purposes only.
* Update header comments to new convention
* Removed "v" from version header.
DefinitelyTyped 
The repository for high quality TypeScript type definitions.
Also see the definitelytyped.org website, although information in this README is more up-to-date.
What are declaration files?
See the TypeScript handbook.
How do I get them?
npm
This is the preferred method. This is only available for TypeScript 2.0+ users. For example:
npm install --save-dev @types/node
The types should then be automatically included by the compiler. See more in the handbook.
For an NPM package "foo", typings for it will be at "@types/foo". If you can't find your package, look for it on TypeSearch.
If you still can't find it, check if it bundles its own typings.
This is usually provided in a "types" or "typings" field in the package.json,
or just look for any ".d.ts" files in the package and manually include them with a /// <reference path="" />.
Other methods
These can be used by TypeScript 1.0.
You may need to add manual references.
How can I contribute?
DefinitelyTyped only works because of contributions by users like you!
Test
Before you share your improvement with the world, use it yourself.
Test editing an existing package
To add new features you can use module augmentation.
You can also directly edit the types in node_modules/@types/foo/index.d.ts, or copy them from there and follow the steps below.
Test a new package
Add to your tsconfig.json:
"baseUrl": "types",
"typeRoots": ["types"],
(You can also use src/types.)
Create types/foo/index.d.ts containing declarations for the module "foo".
You should now be able import from "foo" in your code and it will route to the new type definition.
Then build and run the code to make sure your type definition actually corresponds to what happens at runtime.
Once you've tested your definitions with real code, make a PR contributing the definition by copying types/foo to DefinitelyTyped/foo and adding a tsconfig.json and foo-tests.ts.
Make a pull request
Once you've tested your package, you can share it on DefinitelyTyped.
First, fork this repository. Then inside your repository:
git checkout types-2.0
New work should generally be done on the types-2.0 branch.
If you want your changes to be available to typings users, then you may edit master instead.
Edit an existing package
cd my-package-to-edit- Make changes. Remember to edit tests.
- You may also want to add yourself to "Definitions by" section of the package header.
npm install -g typescript@2.0and runtsc.
When you make a PR to edit an existing package, dt-bot should @-mention previous authors.
If it doesn't, you can do so yourself in the comment associated with the PR.
Create a new package
If you are the library author, or can make a pull request to the library, bundle types instead of publishing to DefinitelyTyped.
If you are adding typings for an NPM package, create a directory with the same name.
If the package you are adding typings for is not on NPM, make sure the name you choose for it does not conflict with the name of a package on NPM.
(You can use npm info foo to check for the existence of the foo package.)
Your package should have this structure:
| File | Purpose |
|---|---|
| index.d.ts | This contains the typings for the package. |
| foo-tests.ts | This contains sample code which tests the typings. This code does not run, but it is type-checked. |
| tsconfig.json | This allows you to run tsc within the package. |
| tslint.json | Enables linting. |
Generate these by running npm run new-package -- new-package-name.
You may edit the tsconfig.json to add new files or to add the "jsx" compiler option.
DefinitelyTyped members routinely monitor for new PRs, though keep in mind that the number of other PRs may slow things down.
For a good example package, see base64-js.
Common mistakes
- First, follow advice from the handbook.
- Formatting: Either use all tabs, or always use 4 spaces. Also, always use semicolons, and use egyptian braces.
interface X {}: An empty interface is essentially the{}type: it places no constraints on an object.interface IFoo {}: Don't addIto the front of an interface name.interface Foo { new(): Foo; }: This defines a type of objects that are new-able. You probably wantdeclare class Foo { constructor(); }.const Class: { new(): IClass; }: Prefer to use a class declarationclass Class { constructor(); }instead of a new-able constant.namespace foo {}: Do not add a namespace just so that theimport * as foosyntax will work. If it is commonJs module with a single export, you should use theimport foo = require("foo")syntax. See more explanation here.getMeAT<T>(): T: If a type parameter does not appear in the types of any parameters, you don't really have a generic function, you just have a disguised type assertion. Prefer to use a real type assertion, e.g.getMeAT() as number. Example where a type parameter is acceptable:function id<T>(value: T): T;. Example where it is not acceptable:function parseJson<T>(json: string): T;. Exception:new Map<string, number>()is OK.
Removing a package
When a package bundles its own types, types should be removed from DefinitelyTyped to avoid confusion. Make a PR doing the following:
- Delete the directory.
- Add a new entry to
notNeededPackages.json.libraryName: Descriptive name of the library, e.g. "Angular 2" instead of "angular2". (May be identical to "typingsPackageName".)typingsPackageName: This is the name of the directory you just deleted.sourceRepoURL: This should point to the repository that contains the typings.asOfVersion: A stub will be published to@types/foowith this version. Should be higher than any currently published version.
- Any other packages in DefinitelyTyped that referenced the deleted package should be updated to reference the bundled types.
To do this, add a
package.jsonwith"dependencies": { "foo": "x.y.z" }.
Lint
To lint a package, just add a tslint.json to that package containing { "extends": "../tslint.json" }. All new packages must be linted.
If a tslint.json turns rules off, this is because that hasn't been fixed yet. For example:
{
"extends": "../tslint.json",
"rules": {
// This package uses the Function type, and it will take effort to fix.
"forbidden-types": false
}
}
(To indicate that a lint rule truly does not apply, use // tslint:disable:rule-name or better, //tslint:disable-next-line:rule-name.)
Only .d.ts files are linted.
Test the linter by running npm run lint -- package-name. Do not use a globally installed tslint.
FAQ
What exactly is the relationship between this repository and the @types packages on NPM?
The types-2.0 branch is automatically published to the @types scope on NPM thanks to types-publisher.
This usually happens within an hour of changes being merged.
Changes to the master branch are also manually merged into the types-2.0 branch, but this takes longer.
I'm writing a definition that depends on another definition. Should I use <reference types="" /> or an import?
If the module you're referencing is an external module (uses export), use an import.
If the module you're referencing is an ambient module (uses declare module, or just declares globals), use <reference types="" />.
What do I do about older versions of typings?
Currently we don't support this, though it is planned.
If you're adding a new major version of a library, you can copy index.d.ts to foo-v2.3.d.ts and edit index.d.ts to be the new version.
I notice some packages having a package.json here.
Usually you won't need this. When publishing a package we will normally automatically create a package.json for it.
A package.json may be included for the sake of specifying dependencies. Here's an example.
We do not allow other fields, such as "description", to be defined manually.
Also, if you need to reference an older version of typings, you must do that by adding "dependencies": { "@types/foo": "x.y.z" } to the package.json.
I notice some tsconfig.json are missing "noImplicitAny": true or "strictNullChecks": true.
Then they are wrong. You can help by submitting a pull request to fix them.
Definitions in types-2.0 seem written differently than in master.
If you're targeting types-2.0, write it like the types-2.0 definitions. If you're targeting master, we may change it to the new style when merging from master to types-2.0.
Can I request a definition?
Here are the currently requested definitions.
License
This project is licensed under the MIT license.
Copyrights on the definition files are respective of each contributor listed at the beginning of each definition file.