GithubHelp home page GithubHelp logo

roblox-ts / types Goto Github PK

View Code? Open in Web Editor NEW
36.0 5.0 59.0 107.6 MB

TypeScript typings for the Roblox platform. Partially handwritten and partially automatically generated.

Home Page: https://www.npmjs.com/package/@rbxts/types

License: MIT License

TypeScript 100.00%
roblox-ts

types's Introduction

A TypeScript-to-Luau Compiler for Roblox

Discord server CI Status Coverage Status
 

Introduction

roblox-ts is an attempt to bridge the abilities of TypeScript to work in a Roblox environment. We break down your code into an abstract syntax tree and emit functionally similar structures in Luau so that the code behaves the same.

Quick start & Documentation

Ready to dive in? Check out the documentation.

Join the Community!

https://discord.roblox-ts.com

Games that use roblox-ts

types's People

Contributors

catgirlinspace avatar christopher-buss avatar cntkillme avatar dependabot-preview[bot] avatar dependabot[bot] avatar dionysusnu avatar evaera avatar gigsd4x avatar griffin-lora avatar grubsteak avatar jacktabscode avatar kampfkarren avatar leonbee0 avatar louiek22 avatar neohertz avatar noahwillcrow avatar ok-nick avatar osyrisrblx avatar overhash avatar pepeeltoro41 avatar rimuy avatar sasial-dev avatar sleitnick avatar snorlaxassist avatar tacheometry avatar ukendio avatar validark avatar vorlias avatar web-flow avatar zachcurtis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

types's Issues

ReadonlyMaps/Sets should get a constructor

I think it is sometimes useful to declare something as a ReadonlyMap/Set, but it would be better if I did not have to use new Map() as ReadonlyMap. I would like to add a constructor to these objects so one can just do new ReadonlyMap() directly.

3rd of NumberSequenceKeypoint is optional

3rd of NumberSequenceKeypoint is optional

NumberSequenceKeypoint Constructors

NumberSequenceKeypoint.new ( number timenumber value )
--Creates a keypoint with a specified time and value.

NumberSequenceKeypoint.new ( number timenumber valuenumber envelop )
--Creates a keypoint with a specified time, value, and envelope.

Object.keys/values/entries type definitions should be improved

Currently, the Object.keys/values/entries functions don't have the best types for our purposes. I wrote this up and thought we could use something similar to this in es.d.ts once #66 gets merged.

declare function keys<T>(o: Array<T>): Array<number>;
declare function keys<T>(o: Set<T>): Array<T>;
declare function keys<K, V>(o: Map<K, V>): Array<K>;
declare function keys<T>(o: T): Array<keyof T>;

declare function values<T>(o: Array<T>): Array<T>;
declare function values<T>(o: Set<T>): Array<true>;
declare function values<K, V>(o: Map<K, V>): Array<V>;
declare function values<T>(o: T): Array<T[keyof T]>;

declare function entries<T>(o: Array<T>): Array<[number, T]>;
declare function entries<T>(o: Set<T>): Array<[T, true]>;
declare function entries<K, V>(o: Map<K, V>): Array<[K, V]>;
declare function entries<T>(o: T): Array<[keyof T, T[keyof T]]>;

Manual type override to-do list

General

setmetatable should be declared

BasePart

BasePart.Touched param #1 should be BasePart

Players

GetPlayerFromCharacter should return Player | undefined (maybe also accept Model?)
GetPlayerByUserId should return Player | undefined
GetPlayers should return Array<Player>
GetCharacterAppearanceAsync should return Model | undefined
GetCharacterAppearanceInfoAsync could have an interface made for the return type
GetFriendsAsync should return FriendPages
GetUserThumbnailAsync should return a typed tuple

CollectionService

GetTagged could be GetTagged<T = Instance>(tag: string): Array<T>;

debug.traceback has arguments

https://github.com/roblox-ts/rbx-types/blob/8ff683572ab90583a00ac4d78902cba731e0bbf0/include/lua.d.ts#L138

Should be

	function traceback(message?: string, level?: number): string;
	function traceback(thread: thread, message?: string, level?: number): string;

This is undocumented (unintentionally) - but basically is on parity with 5.1 debug.traceback ([thread,] [message [, level]]) now - according to @LPGhatguy
https://www.lua.org/manual/5.1/manual.html#pdf-debug.traceback

GetPropertyChangedSignal should only allow strings of properties

Here is the proper definition I came up with:

type GetProperties<T> = {
	[Key in keyof T]-?: Key extends "GetPropertyChangedSignal"
		? never
		: T[Key] extends RBXScriptSignal
		? never
		: (() => any) extends T[Key]
		? never
		: Key
}[keyof T];

GetPropertyChangedSignal<T extends GetProperties<this>>(property: T): RBXScriptSignal;

UDim2.fromOffset, UDim2.fromScale

Two new static constructors were added for UDim2 but they're not enabled yet.

This issue is a reminder to add them.

interface UDim2Constructor {
	fromOffset(x: number, y: number): UDim2;
	fromScale(x: number, y: number): UDim2;
}

os.date is missing overloads

When calling os.date, it will currently always error if you don't use os.date("*t, x).

This means you can't use it in instances such as:

os.date("!*t") // Current date table in UTC time
os.date("%x") // Current date in MM/DD/YY format

This is among other alternatives as specified in the Lua documentation: https://www.lua.org/pil/22.1.html

Clone method does not retain type

fallDown is an Animation, but cloning it has Instance as the type, so you must specifiy as Animation to make sure everything lines up.

image

image

Sort API members based on security level

Possible security levels:

"None" // Default
"LocalUserSecurity" // Command Line
"PluginSecurity" // Plugins
"RobloxScriptSecurity" // CoreScripts
"RobloxSecurity" // ?
"NotAccessibleSecurity" // ?

Higher security levels should include the next lower security level?

Then we can create something like plugin.d.ts which links to include/PluginSecurity.d.ts

Bad type syllogisms

All Instances are Folders, ValueBases, and a few other similar types. This is bad for a few reasons.

Example 1:

if (myInstance.IsA("Folder")) {
	// Do something with folders
} else if (myInstance.IsA("Part"))
	// Do something with parts
}

Example 1 will error on calling "IsA" in the else if clause, since it is of type "never" after it has been determined not to be a Folder (and since all Instances are Folders, it must not be an instance)

Example 2:

if (myInstance.IsA("Part")) {
	// Do something with parts
} else if (myInstance.IsA("Folder"))
	// Do something with folders
}

Example 2 works as a workaround for this issue in this case—however, this does not work if you have an "else" clause at the end, or are dealing with multiple all-encompassing types (like ValueBase with Folder)

Example 3:

if (myInstance.IsA("Folder")) {
	// Do something with folders
} else {
	print("Found another instance of type" + myInstance.ClassName)
}

Since all Instances are Folders, the example 3 will error, because "myInstance" is of type "never" in the else clause.

To work around this, you must use a type assertion (myInstance as Instance), or something similar, in clauses following all-encompassing type guards

Right now I have some pretty ugly code
image
image

Improve definitions for Rbx_Pages

Pages:GetCurrentPage() currently returns unknown.

Unfortunately, it's really hard to define this on a case-by-case basis. Lots of APIs use either Pages or a class that inherits from Pages.

We should convert the class to be a generic class (Rbx_Pages<T = unknown>) so that we can override it per API.

The new type definition for Rbx_Pages.GetCurrentPage() would look like:

interface Rbx_Pages<T = unknown> extends Rbx_Instance {
    Rbx_Pages.GetCurrentPage(): T;
}

`this` parameter should be added to all methods

Adding a this parameter would be a quick and easy way of ensuring that object methods are never called improperly.

Example:

const { FindFirstChild } = part;
FindFirstChild("Hello");
// ERROR: The 'this' context of type 'void' is not assignable to method's 'this' of type 'Instance'.

Every method should be assigned a this which is the class in which it is defined. E.g.

Camera.GetTiltSpeed(): number
// should be
Camera.GetTiltSpeed(this: Camera): number

'sub' does not exist on types 'UDim2' and 'UDim'

Like the title suggests, these methods are not defined in rbx-types, even though their respective 'add' methods are.

E.g.:
new UDim2(3, 3, 3, 3).add(new UDim2(2, 2, 2, 2));
works just fine, while
new UDim2(3, 3, 3, 3).sub(new UDim2(2, 2, 2, 2));
gives the error "Property 'sub' does not exist on type 'UDim2'"

These should be implemented since they are part of the functionality of the respective types (see UDim and UDim2

Promise.resolve() and Promise.reject

Promise.resolve(); // actually: error
// expected: no error

let prom:Promise<void> = Promise.reject('asdfasdf'); // actually: error
// expected: no error

Vector3.Lerp and CFrame.lerp have inconsistent capitalizations

CFrame.Lerp is the title preferred by Roblox documentation. This makes functions expecting something with the "lerp" method unable to take Vector3, and functions expecting something with the "Lerp" method unable to take CFrame, despite the fact that these methods have identical signatures and (essentially the same) behavior.

Implement instances as classes to hide _N properties

declare namespace _Instances {
  class _Instance {
    private _0: never
    Name: string

    IsA(x: "Instance"): this is Instance
    IsA(x: "Folder"): this is Folder
  }

  class _Folder extends _Instance {
    private _1: never
  }
}

interface Instance extends _Instances._Instance {}

interface Folder extends _Instances._Folder {}

const x = {} as Instance

if (x.IsA("Folder")) {
  x // Folder
} else {
  x // Instance
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.