Giter Club home page Giter Club logo

typings's Introduction

dojo/typings

Build Status npm version

This is a repository of Dojo 1 TypeScript Typings (including Dijit and DojoX).

Currently, this repository does not include all the typings for Dijit and DojoX, although Dojo is currently fully covered. The aim is to cover all of Dijit and continue to accept any community contributions for DojoX.

For other packages, because Dojo 2 is built on TypeScript its typings are inherent in its distrubution. The goal for affiliated Dojo 1 projects (like dgrid and dstore is that they will include typings as part of their repository.

Usage

Because Dojo, Dijit and DojoX are such large and complex code bases, the repository tries to break it down into easier to maintain pieces that also allow easy additions, modifications, etc.

Each major namespace is broken down into dojo, dijit and dojox directories, having the major version number in a sub directory within. Currently only Dojo 1.11 is included. These typings should work for most older versions of Dojo post 1.7, though it may include some functionality that is not present in those older releases.

The ambient declarations that mirror the Dojo namespaces are indexed via the index.d.ts file located in each directory and the ambient module names are then declared in a single file for the namespace called modules.d.ts. To utilise in a project, where you are going to import several modules via an AMD loader, you would likely just need to reference the modules.d.ts. If you need to modify the names of the ambient modules to match your runtime environment, then you would copy the modules.d.ts and rename all the modules as required.

Basic usage would be to include the index.d.ts and likely modules.d.ts in files used either by tsc or in your tsconfig.json or referenced within your TypeScript files. The wiki contains some basic how to instructions.

The easiest way to install the typings is via npm:

> npm install dojo-typings --save-dev

Building

The repository has a Gruntfile.js and a development dependency of grunt that can help validate any changes to the typings. After cloning the repository and running npm install, you can then run grunt or grunt dev which will compile the files with tsc as well as run tslint against the core files.

Examples

There are examples of how to use the typings in a TypeScript project located in the examples directory of this repository.

Limitations

Typings are global

At the time of this writing (TypeScript 1.7/1.8), typings are global and absolute. In order to change module resolution from dojo/... the modules.d.ts will need to be updated.

String Literals

The current typings are built around TypeScript 1.7. TypeScript 1.8 introduced string literal types and there are improvements that can be made to the typings, several of them noted as comments in the existing typings.

Note: while the repository currently uses TypeScript 1.8 as its development dependency we haven't started using the string literals yet.

Contributing

Contributions to this repository are very much welcomed! If you wish to contribute to this repository, please see our Contributing Guidelines.

typings's People

Contributors

agubler avatar bitranch avatar bryanforbes avatar cdschmitz avatar dasa avatar davewilton avatar dependabot[bot] avatar devpaul avatar edhager avatar heikostudt avatar jacobroufa avatar jcfranco avatar jkieboom avatar kitsonk avatar maier49 avatar matt-gadd avatar mmckenziedev avatar msssk avatar pantosha avatar rorticus avatar roytinker avatar sindilevich avatar vansimke avatar wuhi avatar ycabon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typings's Issues

Upgrade typings to TS 1.8

Mostly involves using string literal types where appropriate.

Also, the README needs to be updated since it's still claiming that TS 1.8 is in development, where the current release version is 1.8.10.

Modelling Plugins in Typings

In TS 2.0, we will be able to use wildcards in module names to better represent typings (see: Microsoft/TypeScript#6615). This is currently in typescript@next and a brief test show this works, so we need to fold this in to be ready for TS 2.0.

Errors with Typescript 2.6 using --strictFunctionTypes

I should note that this is using version 1.11.9:

$ tsc --strictFunctionTypes
dojo/1.11/_base.d.ts(1853,4): error TS2411: Property ''text'' of type '(xhr: { responseText: string; }) => string' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.
dojo/1.11/_base.d.ts(1854,4): error TS2411: Property ''json'' of type '(xhr: { responseText: string; }) => GenericObject' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.
dojo/1.11/_base.d.ts(1855,4): error TS2411: Property ''json-comment-filtered'' of type '(xhr: { responseText: string; }) => GenericObject' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.
dojo/1.11/_base.d.ts(1856,4): error TS2411: Property ''javascript'' of type '(xhr: { responseText: string; }) => any' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.
dojo/1.11/_base.d.ts(1857,4): error TS2411: Property ''xml'' of type '(xhr: { responseXML: string; }) => Document' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.
dojo/1.11/_base.d.ts(1858,4): error TS2411: Property ''json-comment-optional'' of type '(xhr: { responseText: string; }) => GenericObject' is not assignable to string index type '(xhr: { responseText?: string; responseXML?: string; }) => any'.

EventedConstructor incorrectly typed

Evented isn't created with declare. It's a traditional es5 class function.

define(["./aspect", "./on"], function(aspect, on){
	// module:
	//		dojo/Evented

 	"use strict";
 	var after = aspect.after;
	function Evented(){
		// summary:
		//		A class that can be used as a mixin or base class,
		//		to add on() and emit() methods to a class
		//		for listening for events and emitting events:
		// example:
		//		|	define(["dojo/Evented", "dojo/_base/declare", "dojo/Stateful"
		//		|	], function(Evented, declare, Stateful){
		//		|		var EventedStateful = declare([Evented, Stateful], {...});
		//		|		var instance = new EventedStateful();
		//		|		instance.on("open", function(event){
		//		|		... do something with event
		//		|	 });
		//		|
		//		|	instance.emit("open", {name:"some event", ...});
	}
	Evented.prototype = {
		on: function(type, listener){
			return on.parse(this, type, listener, function(target, type){
				return after(target, 'on' + type, listener, true);
			});
		},
		emit: function(type, event){
			var args = [this];
			args.push.apply(args, arguments);
			return on.emit.apply(on, args);
		}
	};
	return Evented;
});

This needs fixing:

interface EventedConstructor extends _base.DeclareConstructor<Evented> {
		new (params?: Object): Evented;
	}

Add typing for some dojox/widget

Add typing for:

  • dojox/widget/DialogSimple
  • dojox/widget/Dialog
  • dojox/widget/Toaster

PR is #1

Note: I should be covered by both a personal CLA and a corporate CLA via Holmes Corporation. Take your pick. :)

Property 'inherited' does not exist on type <...>

Hi,

I'm looking into seeing if I can convert an existing Dojo project to TypeScript using these typings and I'm having trouble calling this.inherited(arguments) in classes that I am declaring.

To reproduce, simply add the following to the Dialog class definition in the example/basicApp project:

    destroy() {
        this.inherited(arguments);
    }

which gives the error "src/app/Dialog.ts(24,8): error TS2339: Property 'inherited' does not exist on type 'Dialog'" rather than just working.

Is there a different way to call the base classes method from an inheriting class? I can't seem to find any references of how to do this in the repository.

tsc --version
Version 2.6.2

Thanks in advance

Publish 1.11.0-pre to npm

I don't know what your exact timeframe is for 1.11 final, but would it be possible for you to publish the 1.11.0-pre of the typings to npm? I'm using them with 1.10.4 now and the current npm release is missing some key dijit definitions that are in pre.

Thanks!

Compile errors with TypeScript 2.4.1

These are the errors I'm getting with tsc on the master branch:

$ tsc index.d.ts 
dijit/1.11/form.d.ts(1589,13): error TS2430: Interface 'NumberSpinner' incorrectly extends interface '_Spinner'.
  Types of property 'filter' are incompatible.
    Type '(value: number) => number' is not assignable to type '<T>(val: T) => T'.
      Types of parameters 'value' and 'val' are incompatible.
        Type 'T' is not assignable to type 'number'.
dijit/1.11/form.d.ts(1627,13): error TS2430: Interface 'NumberTextBox' incorrectly extends interface 'RangeBoundTextBox'.
  Types of property 'filter' are incompatible.
    Type '(value: number) => number' is not assignable to type '<T>(val: T) => T'.
      Types of parameters 'value' and 'val' are incompatible.
        Type 'T' is not assignable to type 'number'.
dijit/1.11/form.d.ts(1686,13): error TS2430: Interface 'SimpleTextarea' incorrectly extends interface 'TextBox'.
  Types of property 'filter' are incompatible.
    Type '(value: string) => string' is not assignable to type '<T>(val: T) => T'.
      Types of parameters 'value' and 'val' are incompatible.
        Type 'T' is not assignable to type 'string'.
dijit/1.11/layout.d.ts(89,13): error TS2430: Interface 'LayoutContainer' incorrectly extends interface '_LayoutWidget'.
  Types of property 'removeChild' are incompatible.
    Type '<T extends _WidgetBase>(child: T) => void' is not assignable to type '<T extends _WidgetBase>(widget: number | T) => void'.
      Types of parameters 'child' and 'widget' are incompatible.
        Type 'number | T' is not assignable to type '_WidgetBase'.
          Type 'number' is not assignable to type '_WidgetBase'.

Intern and leadfoot cause error TS2307: Cannot find module 'dojo/Promise'.

This definitely used to work, so I'm not sure what is going on here. I have referenced the typings for dojo & intern in a tsd.d.ts which looks like this:

/// <reference path="node_modules/dojo-typings/custom/intern/intern.d.ts" />
/// <reference path="node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts" />

/// <reference path="node_modules/dojo-typings/dojo/1.11/index.d.ts" />
/// <reference path="node_modules/dojo-typings/dojo/1.11/modules.d.ts" />
/// <reference path="node_modules/dojo-typings/dojo/1.11/promise.d.ts" />
/// <reference path="node_modules/dojo-typings/dijit/1.11/index.d.ts" />
/// <reference path="node_modules/dojo-typings/dijit/1.11/modules.d.ts" />
/// <reference path="node_modules/dojo-typings/dojox/1.11/index.d.ts" />
/// <reference path="node_modules/dojo-typings/dojox/1.11/modules.d.ts" />

/// <reference path="node_modules/dojo-typings/custom/dgrid/1.1/dgrid.d.ts" />
/// <reference path="node_modules/dojo-typings/custom/dstore/1.1/dstore.d.ts" />

Whenever I build I get the following error

C:\temp\InternIssue>node "C:\temp\InternIssue\node_modules\typescript\bin\tsc"
node_modules/dojo-typings/custom/intern/intern.d.ts(7,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/intern/intern.d.ts(48,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/intern/intern.d.ts(73,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/intern/intern.d.ts(129,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/intern/intern.d.ts(144,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/intern/intern.d.ts(277,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts(358,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts(422,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts(1664,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts(2237,27): error TS2307: Cannot find module 'dojo/Promise'.
node_modules/dojo-typings/custom/leadfoot/leadfoot.d.ts(2366,27): error TS2307: Cannot find module 'dojo/Promise'.

C:\temp\InternIssue>node "C:\temp\InternIssue\node_modules\typescript\bin\tsc" -v
Version 2.2.2

I rolled back to 2.2.2 because I know it used to work back then. My tsconfig looks like this:

{
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
    },
    "module": "amd",
    "moduleResolution": "node",
    "target": "es5",
    "noImplicitAny": false,
    "sourceMap": true
  }
}

Cannot find name ActiveXObject

Description: When I use this module, it throws an error because it cannot find ActiveXObject.

Typescript-version: 2.3.2

CompilerOptions:

  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "declaration": false,
    "experimentalDecorators": false,
    "module": "amd",
    "moduleResolution": "node",
    "noImplicitThis": false,
    "noImplicitUseStrict": false,
    "noUnusedParameters": false,
    "noUnusedLocals": false,
    "sourceMap": true,
    "strictNullChecks": false,
    "target": "es5",
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "preserveConstEnums": true,
    "suppressImplicitAnyIndexErrors": true,
    "lib": [
      "dom",
      "es7",
      "es2017.object"
    ],
    "outDir": "tmp"
  }

Steps to reproduce:

Expected result: No Error
Actual result:

node_modules/dojo-typings/dojo/1.11/_base.d.ts(1867,32): error TS2304: Cannot find name 'ActiveXObject'.
node_modules/dojo-typings/dojo/1.11/dojo.d.ts(411,30): error TS2304: Cannot find name 'ActiveXObject'.
node_modules/dojo-typings/dojo/1.11/request.d.ts(431,32): error TS2304: Cannot find name 'ActiveXObject'

Version: 1.11.6

Any additional information:
I tried to add ActiveXObject manually, which also did not work:

declare const ActiveXObject: (type: string) => void;

Can't use Deferred as a type

Repro case

import Deferred = require("dojo/Deferred");

interface SomeInterface {
  dfd: Deferred<SomeType>;
  // ...
}

export function process(): IPromise<SomeType> {
  let dfd = new Deferred<SomeType>();
  // ...
  return dfd;
}

Problem

The repro case results in a TS2304: Cannot find name 'Deferred' compiler message for the usage of Deferred as type in the interface, but not for the usage as constructor in the function.

Solution

Changing the declaration Deferred in module.d.ts to

declare module 'dojo/_base/Deferred' {
    type Deferred = dojo._base.Deferred;
    const Deferred: dojo._base.DeferredConstructor;
    export = Deferred;
}

fixes the problem.

EventedConstructor has two constructors of different types

Using a current typescript transpiler (^3.9.7), we got the error

TS2510 --- Base constructors must all have the same return type.

This is due to EventedConstructor defines the constructor as
new (params?: Object): Evented;
but the base class _base.DeclareConstructor has one defined by:
new (...args: any[]): Evented & DeclareCreatedObject;

Therefore, Evented could not be used as a base class; I will attach an PR

Incorrect declare typings

The declare typings are not applying DeclareCreatedObject to the props object in the declare method. This means that you can't use this.inherited from inside a function passed into declare.

See the following example,

https://codesandbox.io/s/cool-galileo-sv5n3?file=/src/index.ts

It seems like it would be enough to add DeclareCreatedObject to the ThisType for each relevant entry in the Declare interface.

i.e.,

<A, B>(superClass: DeclareConstructor<A> | [DeclareConstructor<A>], props: B & ThisType<DeclareCreatedObject & A & B>): DeclareConstructor<A & B>;

Additional dijit/layout typing

I'm working on a PR for the following dijit/layout related typing:

  • dijit/_Contained
  • dijit/_WidgetsInTemplateMixin
  • dijit/layout/_LayoutWidget
  • dijit/layout/StackContainer
  • dijit/layout/StackController

Also adding module definitions to make some dijit base classes importable:

  • dijit/_WidgetBase
  • dijit/_TemplatedMixin

(Let me know if these collide with anything @kitsonk is working on.)

Move to UMD Definitions

TypeScript supports the concept of having a type definition as a "module" which allows it then to be further consumed and namespaced downstream. Currently the way our type definitions are defined are as "global" which means that tooling (like typings/typings) cannot easily namespace modules, which would be great. It also means that it doesn't auto concatenate the files.

I am going to start this work on a new branch, to see how difficult it would be.

Deferred: arguments to `resolve` and `reject` should be optional

With the current typings, it's impossible to make a Deferred that does not result in a value. Also, it's not possible not to supply an error on rejection.

These may not be the standard or intended use cases for Deferred, but there are situations where it comes in handy, and there's nothing that prevents it on the JavaScript side.

Add widget example

It would be nice to have an advanced example that shows how to make a widget that extends _WidgetBase and _TemplatedMixin. I see some examples in github repositories, but it would be good to get an example from SitePen that demonstrates best practices.

Is the dojo/fx/Toggler functional?

Hello,
I am trying to use the Toggler and am having issues.

Now I am VERY green to typescript, but looking at dojo-typings/dojo/1.11/fx.d.ts I can see the toggler declared, but no export.

Should I be able to import the dojo/fx/Toggler as is?

dojo.date.Date namespace hides global Date in dojo.date typings

The dojo/date functions taking a Date object fail because the dojo.date.Date namespace is used instead of the global Date. Thus, both of these produce an error in TS since it's looking for a dojo.date.Date:

const dt = new Date();
toISOString(dt);
isLeapYear(dt);

Unable to inherit from dojo/Stateful or dojo/Evented with dojo/_base/declare

Hey there,

It's my first time doing stuff like that on GitHub, so don't blow me away please. ;-)

Currently I write some experimental dojo 1.x modules with TypeScript and therefore I use this typings.
It works very well, until i try to inherit from 'dojo/Stateful' or 'dojo/Evented'. When i try to mix these modules into my class with 'dojo/_base/declare', the TypeScript compiler claims, that these interfaces do not extend 'dojo._base.DeclareConstructor'.

So to avoid this, i did some changes in the modules.d.ts & the dojo.d.ts files:

Changes in dojo.d.ts:

I added an StatefulConstructor like this:

interface StatefulConstructor extends dojo._base.DeclareConstructor<Stateful> {
  new (params: Object): Stateful;
}

Get dojo/Evented to work like expected, I modified the dojo.EventedConstructor:

interface EventedConstructor extends dojo._base.DeclareConstructor<Evented> {
  new (params: Object): Evented;
}

Changes in module.d.ts:

In the module.d.ts file i created a module 'dojo/Stateful', so i can reference it from my modules.

declare module 'dojo/Stateful' {
  const Stateful: dojo.StatefulConstructor;
  export = Stateful;
}

I don't know if this is the right way to do it, but if so i would submit these changes to this repository?

declareDecorator does not bring along getters and setters

If you use the declareDecorator on a class all the getters and setters are lost.

I was having issues making a PR so here is the updated version of https://github.com/dojo/typings/blob/master/examples/basicApp/src/app/declareDecorator.ts:

import dojoDeclare from 'dojo/_base/declare';

/**
 * A decorator that converts a TypeScript class into a declare constructor.
 * This allows declare constructors to be defined as classes, which nicely
 * hides away the `declare([], {})` boilerplate.
 */

export default function (... mixins: Object[]) {
	return function (target: Function) {
		let declared = dojoDeclare(mixins, target.prototype);

		// Bring getters and setters along for the ride
		Object.keys(target.prototype).forEach(key => {
			let descrip = Object.getOwnPropertyDescriptor(target.prototype, key);
			if (typeof descrip.get == 'function' || typeof descrip.set == 'function') {
				Object.defineProperty(declared.prototype, key, descrip);
			}
		});

		return declared;
	};
}

`dstore/legacy/DstoreAdapter` resolves to a non-module entity.

Currently it is possible to import dstore modules like dstore/Memory via import * as Module from 'dstore/{module}'. The module declaration treats dstore/legacy/DstoreAdapter as a class, so it blindly allows importing it as the default export from the package, which is incorrect.

Typo in NumberFormatOptions definition

The following statement shows a TypeScript error even if it is valid:

number.format(value, { pattern: '####', fractional: false });

This happens because there's an error in the NumberFormatOptions interface definition: factional instead of fractional (inside dojo.d.ts).

Issues with noimplicitany and dijit

I ran into the following errors on TypeScript versions 2.4.0 and 2.4.2:

node_modules/dojo-typings/custom/dstore/1.1/dstore.d.ts(81,3): error TS7010: 'constructor', which lacks return-type annotation, implicitly has an 'any' return type.
node_modules/dojo-typings/dijit/1.11/form.d.ts(283,13): error TS2430: Interface '_DateTimeTextBox<T>' incorrectly extends interface 'RangeBoundTextBox'.
  Types of property 'pattern' are incompatible.
    Type '(options?: DateLocaleFormatOptions | undefined) => string' is not assignable to type 'string | ConstraintsToRegExpString<RangeBoundTextBoxConstraints>'.
      Type '(options?: DateLocaleFormatOptions | undefined) => string' is not assignable to type 'ConstraintsToRegExpString<RangeBoundTextBoxConstraints>'.
        Types of parameters 'options' and 'constraints' are incompatible.
          Type 'RangeBoundTextBoxConstraints' is not assignable to type 'DateLocaleFormatOptions | undefined'.
            Type 'RangeBoundTextBoxConstraints' has no properties in common with type 'DateLocaleFormatOptions'.

The first one only happens with noimplicitany.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.