Comments (7)
I think you can use an intersection. Since you're returning a class, I think singleton
is what you want:
def self.enhance: () -> singleton(A & Ext)
from rbs.
That could work. But how can I make it work for "any subclass of A"?
from rbs.
Oh, right. Replace A
with self
:
def self.enhance: () -> singleton(self & Ext)
I didn't try it and I'm just starting to get acquainted with RBS. Maybe it's singleton(A) & singleton(Ext)
, or maybe both are the same, I don't know 🤷♂️
from rbs.
I'm getting errors on a bit of a different use-case, but similar syntax. So, for that example above:
module Ext
def self.enhance(klass)
Class.new(klass) do
include Ext::InstanceMethods
end
end
module InstanceMethods
def bar;end
end
end
Now, if I type it like this:
module Ext
def self.enhance: (singleton(A)) -> singleton(A)
end
When running the runtime type checker on:
class A
def foo; ; end
end
B = Ext.enhance(A) #=> this works
C = Ext.enhance(B) #=> this blows: RBS::Test::Tester::TypeError: TypeError: [.enhance] ArgumentTypeError: expected `singleton(::A)` but given `#<Class:0x000055970ae64258>`
I didn't try it and I'm just starting to get acquainted with RBS.
Likewise :)
from rbs.
It's taking your A
literally. You need [A]
. Maybe this would work:
module Ext
def self.enhance: [A] (singleton(A)) -> singleton(A) & singleton(Ext::InstanceMethods)
end
from rbs.
Yeah, it's not supported at all.
Class.new(klass) do
include Ext::InstanceMethods
end
The code requires a concept of type of a class object which includes a module... I don't think we can implement it now.
from rbs.
:( sad to hear, but it's understandable that one can't ship everthing in one go.
Do you have ideas on how this could look like in the future?
from rbs.
Related Issues (20)
- unhandled exception was raised when dependencies are mismatched between Gemfile.lock and rbs_collection.lock.yaml
- `rbs prototype rb` fails due to syntax error HOT 1
- `rbs prototype rb` fails when include target contains variables
- A sound and complete type for Enumerable#inject HOT 1
- Feature proposal: `rbs diff` command HOT 1
- Feature proposal: `rbs todo` command
- Should gems include private methods and constants in their RBS files? HOT 1
- Allow Type Variable constraints to be arbitrary types HOT 1
- `Enumerable#to_set` accepts a block
- `SimpleDelegator` is missing HOT 1
- Many Kernel methods are defined as Object methods HOT 6
- URI is missing HOT 3
- Logger is missing
- Set#intersect?, Set#disjoint? signatures are too narrow HOT 1
- The `range[T]` type definition is to restrictive
- `_Range[T]` shouldn't return `T?` for `begin` and `end`
- override a function with a block fails
- Singleton does not have method `instance` HOT 1
- add an `assert_const_type`
- Cannot specify type variables for `instance` HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbs.