Skip to content

Conversation

@clagiordano
Copy link
Contributor

@clagiordano clagiordano commented Apr 8, 2020

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:

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

@seanohue
Copy link

seanohue commented Apr 8, 2020

Amazing, much needed!

@seanohue
Copy link

seanohue commented Apr 8, 2020

How can I help?

@clagiordano
Copy link
Contributor Author

clagiordano commented Apr 8, 2020

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 clagiordano changed the title [WIP] Add type definitions to allow editor autocompletion / intellisense Add type definitions to allow editor autocompletion / intellisense Dec 6, 2020
@clagiordano clagiordano marked this pull request as ready for review December 6, 2020 23:33
@nelsonsbrian
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants