RanvierMUD / core

Core engine code for Ranvier
https://ranviermud.com
MIT License
45 stars 40 forks source link

Add type definitions to allow editor autocompletion / intellisense #116

Open clagiordano opened 4 years ago

clagiordano commented 4 years ago

This PR add a folder types with one definition file for every src classes, with same name as original class and a .d suffix, these definition are exposed using an index.d.ts on repository root that import and re export all available definitions.

These additions allow an editor like vscode to automatically suggest methods, properties and arguments, making more easier especially for new users the core classes usages.

I hope that this work could be considered useful.

Available definitions:

Some working examples:

Methods list: methods_list

Function argument list: arguments_list

This PR also add typescript and @types/node as dev dependency to validate definitions file using this command:

npx tsc --esModuleInterop true index.d.ts
seanohue commented 4 years ago

Amazing, much needed!

seanohue commented 4 years ago

How can I help?

clagiordano commented 4 years ago

We only need to create a file for every missing definition that export a definition like this:

Broadcast.d.ts

export namespace Broadcast {
    let sampleProperty: type;
    function methodSignature(arg1: type, arg2: type); 
}

on index.d.ts add an export for every definition class or group like this:

export { Broadcast, Broadcastable } from './types/Broadcast';

EDIT:

there are too many documented modes to do this but after a lot of tests, a better way to write a definition seems something like that:

export declare class SampleClass extends someBaseClass {
    sampleProperty: sampleType;
    sampleMethod(sampleArg: sampleType): sampleReturnType;
}

The last example allow to declare: class, extended class, properties and methods, also allow declaration of functions i.e. Scriptable or Metadatable

export declare function MyFunction(sampleArg: sampleType): sampleReturnType;
seanohue commented 4 years ago

I'll be trying to pull this into my fork at some point this weekend so I can contribute & test it 😻

clagiordano commented 4 years ago

Thanks @seanohue it would really helpful!

nelsonsbrian commented 3 years ago

Having those autocompletions and typing from the .d.ts or ts-core is AMAZING!