core icon indicating copy to clipboard operation
core copied to clipboard

Add type definitions to allow editor autocompletion / intellisense

Open clagiordano opened this issue 5 years ago • 6 comments

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:

  • [x] Account
  • [x] AccountManager
  • [x] AreaAudience
  • [x] AreaFactory
  • [x] AreaFloor
  • [x] Area
  • [x] AreaManager
  • [x] AreaOfEffectDamage
  • [x] AreaOfEffectHeal
  • [x] AttributeFactory
  • [x] Attribute
  • [x] AttributeFormula
  • [x] Attributes
  • [x] BehaviorManager
  • [x] Broadcast
  • [x] Broadcastable
  • [x] BundleManager
  • [x] ChannelAudience
  • [x] Channel
  • [x] ChannelManager
  • [x] Character
  • [x] Command
  • [x] CommandManager
  • [x] CommandQueue
  • [x] CommandType
  • [x] Config
  • [x] Damage
  • [x] Data
  • [x] DataSource
  • [x] DataSourceRegistry
  • [x] EffectableEntity
  • [x] EffectFactory
  • [x] EffectFlag
  • [x] Effect
  • [x] EffectList
  • [x] EntityFactory
  • [x] EntityLoader
  • [x] EntityLoaderRegistry
  • [x] EquipErrors
  • [x] EventManager
  • [x] EventUtil
  • [x] GameEntity
  • [x] GameServer
  • [x] Heal
  • [x] Helpfile
  • [x] HelpManager
  • [x] Inventory
  • [x] ItemFactory
  • [x] Item
  • [x] ItemManager
  • [x] ItemType
  • [x] Logger
  • [x] Metadatable
  • [x] MobFactory
  • [x] MobManager
  • [x] Npc
  • [x] PartyAudience
  • [x] Party
  • [x] PartyManager
  • [x] Player
  • [x] PlayerManager
  • [x] PlayerRoles
  • [x] PrivateAudience
  • [x] QuestFactory
  • [x] QuestGoal
  • [x] QuestGoalManager
  • [x] Quest
  • [x] QuestReward
  • [x] QuestRewardManager
  • [x] QuestTracker
  • [x] RoleAudience
  • [x] RoomAudience
  • [x] RoomFactory
  • [x] Room
  • [x] RoomManager
  • [x] Scriptable
  • [x] SkillErrors
  • [x] SkillFlag
  • [x] Skill
  • [x] SkillManager
  • [x] SkillType
  • [x] TransportStream
  • [x] Util
  • [x] WorldAudience

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

clagiordano avatar Apr 08 '20 17:04 clagiordano

Amazing, much needed!

seanohue avatar Apr 08 '20 17:04 seanohue

How can I help?

seanohue avatar Apr 08 '20 17:04 seanohue

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;

clagiordano avatar Apr 08 '20 17:04 clagiordano

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

seanohue avatar Sep 17 '20 16:09 seanohue

Thanks @seanohue it would really helpful!

clagiordano avatar Sep 17 '20 17:09 clagiordano

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

nelsonsbrian avatar Dec 07 '20 04:12 nelsonsbrian