Skip to content

TypeScript Definitions for Magento 2

License

OSL-3.0, Unknown licenses found

Licenses found

OSL-3.0
LICENSE.txt
Unknown
COPYING.txt
Notifications You must be signed in to change notification settings

magento/ts-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Magento 2 TypeScript Definitions

This package contains type definitions for some Magento 2 libraries (https://magento.com/). If you're wanting to use TypeScript in a Magento 2 project you will won't be able to use Magento 2 libraries in your TypeScript without definitions for those libraries.

Installation

yarn add --dev https://github.com/magento/ts-types.git

or

npm install --save-dev https://github.com/magento/ts-types.git

Current Supported Magento Libraries

  • mage/translate: $t
  • uiClass: uiClass
  • uiElement: uiElement
  • uiCollection: uiCollection
  • uiComponent: uiComponent
  • uiRegistry: uiRegistry

If a library you desire isn't included yet please open an issue or pull request to this repository.

Usage

You can import the modules using the standard TypeScript import syntax:

import * as $t from 'mage/translate';
import * as uiClass from 'uiClass';
import * as uiElement from 'uiElement';
import * as uiCollection from 'uiCollection';
import * as uiComponent from 'uiComponent';
import * as uiRegistry from 'uiRegistry';

Then you're able to use the libraries as you would in normal JavaScript:

// Translate
$t('Translate this string');

// Classes
class MyComponent extends uiComponent {

}

When TypeScript compiles the .ts files to JavaScript it will maintain the module name in the require dependencies. Resulting in the actual libraries being imported in the browser.

About

TypeScript Definitions for Magento 2

Resources

License

OSL-3.0, Unknown licenses found

Licenses found

OSL-3.0
LICENSE.txt
Unknown
COPYING.txt

Code of conduct

Stars

Watchers

Forks

Packages

No packages published