Skip to content

Repository files navigation

jQuery — highly modular TypeScript type definitions

  • Based on the API documentation for jQuery 3.1.
  • Ships type definitions only — bring your own jQuery.
  • Separate interfaces defined for most objects / functions for easy reusability.
  • Most interface declarations are in separate files for easy browsing.
  • MIT licensed.

Usage

Install the types alongside jQuery:

npm install jquery --save
npm install jquery-ts --save-dev

Then reference the interfaces in TypeScript. Every interface lives under the jQuery namespace:

import type jQuery = require('jquery-ts')

function render($: jQuery.IStatic): void {
	$('body').append('<h1>Success!</h1>')

	const deferred: jQuery.IDeferred = $.Deferred()
	deferred.catch(() => console.error('rejected'))
}

Use the interfaces (jQuery.IStatic, jQuery.IInstance, jQuery.IDeferred, jQuery.IPromise, …) to type your own jQuery values, function parameters, and return types.

Upgrading

Two changes affect existing consumers:

jquery-ts no longer bundles jQuery

This package is now types-only. Earlier versions re-exported the jQuery library itself and exposed an initJQuery helper — both have been removed:

  • The import $ from 'jquery-ts' default export is gone. Import jQuery from the jquery package directly and use jquery-ts for its types.

  • The initJQuery(window) helper is gone. It relied on the runtime re-export and never worked reliably against modern jQuery (which self-binds to the ambient window). To use jQuery with a specific window in Node, call the jQuery factory yourself:

    import { JSDOM } from 'jsdom'
    import jQueryFactory from 'jquery'
    
    const { window } = new JSDOM('<!DOCTYPE html>')
    const $ = jQueryFactory(window as unknown as Window)

Add jquery to your own dependencies (it is no longer pulled in transitively) and move jquery-ts to devDependencies, since it contributes types only.

Bower support dropped

Install from npm instead of Bower, and remove the Bower-specific paths mapping that older versions of this README asked you to add to your tsconfig.json:

// No longer needed — delete this block:
"paths": { "*": ["bower_components/*", "*"] }

Modern module resolution finds the package under node_modules automatically.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages