Skip to content

Commit

Permalink
Merge pull request #7 from mugi-uno/update_readme
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
mugi-uno authored Jan 17, 2021
2 parents 0928d23 + 6654a50 commit 68f045a
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 54 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.md
130 changes: 125 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,136 @@ gem install rbs2ts
rbs2ts convert type.rbs
```

## Example

from RBS

```
type TypeofInteger = Integer
type TypeofFloat = Float
type TypeofNumeric = Numeric
type TypeofString = String
type TypeofBool = Bool
type TypeofVoid = void
type TypeofUntyped = untyped
type TypeofNil = nil
type IntegerLiteral = 123
type StringLiteral = 'abc'
type TrueLiteral = true
type FalseLiteral = false
type UnionType = String & Integer & Bool
type IntersectionType = String | Integer | Bool
type ArrayType = Array[String]
type TupleType = [ ]
type TupleEmptyType = [String, Integer]
type OptionalType = String?
type RecordType = {
s: String,
next: {
i: Integer,
f: Float
}?
}
class Klass
attr_accessor a: String
attr_reader b: Integer
attr_writer c: Bool
attr_reader r: {
d: String,
e: {
f: String,
g: String?
}?
}
def to_s: () -> String
def tuple: () -> [{ s: String, f: Float }?]
end
```

to TypeScript

```typescript
export type TypeofInteger = number;

export type TypeofFloat = number;

export type TypeofNumeric = number;

export type TypeofString = string;

export type TypeofBool = boolean;

export type TypeofVoid = void;

export type TypeofUntyped = any;

export type TypeofNil = null;

export type IntegerLiteral = 123;

export type StringLiteral = "abc";

export type TrueLiteral = true;

export type FalseLiteral = false;

export type UnionType = string & number & boolean;

export type IntersectionType = string | number | boolean;

export type ArrayType = string[];

export type TupleType = [];

export type TupleEmptyType = [string, number];

export type OptionalType = string | null | undefined;

export type RecordType = {
s: string;
next: {
i: number;
f: number;
} | null | undefined;
};

export namespace Klass {
export type a = string;
export type b = number;
export type r = {
d: string;
e: {
f: string;
g: string | null | undefined;
} | null | undefined;
};
export type toSReturnType = string;
export type tupleReturnType = [({
s: string;
f: number;
} | null | undefined)];
};
```

---

## ToDo

- [x] Literal type
- [ ] Interface type
- [ ] Literal type
- [ ] Tuple Type
- [ ] Base Types
- [ ] Method Type (Argument Types and Return Types)
- [ ] Class declaration
- [x] Literal type
- [x] Tuple Type
- [x] Base Types
- [x] Method Type (Argument Types and Return Types)
- [x] Class declaration
- [ ] Module declaration
- [ ] Interface declaration
82 changes: 33 additions & 49 deletions spec/fixtures/test.rbs
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
type StrOrIntOrBool = String | Integer | Bool
type StrAndIntAndBool = String & Integer & Bool

type X = String & Integer | Bool
type Y = String & (Integer | Bool)

type Arr = Array[(Integer | String?)?]

type Base = {
bool: bool,
void: void,
any: any,
nil: nil
}

type Foo = {
str: String,
str_o: String?,
int: Integer,
int_o: Integer?,
bool: Bool,
bool_o: Bool?
}

type Bar = {
type: String,
address: {
zipcode: String,
tel: String?
type TypeofInteger = Integer
type TypeofFloat = Float
type TypeofNumeric = Numeric
type TypeofString = String
type TypeofBool = Bool
type TypeofVoid = void
type TypeofUntyped = untyped
type TypeofNil = nil

type IntegerLiteral = 123
type StringLiteral = 'abc'
type TrueLiteral = true
type FalseLiteral = false

type UnionType = String & Integer & Bool
type IntersectionType = String | Integer | Bool

type ArrayType = Array[String]

type TupleType = [ ]
type TupleEmptyType = [String, Integer]

type OptionalType = String?

type RecordType = {
s: String,
next: {
i: Integer,
f: Float
}?
}

type Baz = {
foo: Foo,
bar: Bar
}

type FooAndBar = Foo & Bar

type FooOrBar = Foo | Bar

class Klass
attr_reader a: String
attr_writer b: Integer
attr_accessor c: Boolean
attr_accessor a: String
attr_reader b: Integer
attr_writer c: Bool

attr_reader r: {
d: String,
Expand All @@ -53,12 +44,5 @@ class Klass
}

def to_s: () -> String
def self.new: () -> AnObject
def self?.sqrt: (Numeric) -> Numeric
def tuple: () -> [{ s: String, f: Float }?]
end

type TupleEmpty = [ ]
type Tuple1 = [String]
type Tuple2 = [Integer, Integer]
type Tuple3 = [String, Integer?, Bool]
type Tuple4 = [{ s: String, i: Integer }]

0 comments on commit 68f045a

Please sign in to comment.