Comments (2)
I see. But I think inheritance can be used
import crypto
schema Obj:
id: str
schema MySchema1(Obj):
id = crypto.uuid()
name: str
schema MySchema2(Obj):
displayName: str
collectIDs = lambda objs: [Obj] {
ret = [v.id for v in objs]
}
res1 = collectIDs([MySchema1 {name = ""}])
res2 = collectIDs([MySchema2 {id = "id", displayName = ""}])
I understand duck types like Go and Typescript, which can be assigned values as long as they have a partial order relationship rather than an explicit declaration. KCL considered this feature at the beginning of its design, but still adopts strict type inheritance and checking for types defined using the schema keyword, because in the schema, besides attributes, other logic can be defined. In addition, KCL also has the protocol keyword, which is a more stringent type of schema that only allows attributes to be defined within it. Perhaps this semantics can be extended.
schema ASchema:
id: str
name: str
protocol ASchemaProtocol:
id: str
a: ASchemaProtocol = ASchema {....}
from kcl.
oh nice, yes this works great, thanks!
from kcl.
Related Issues (20)
- [Enhancement] Add example highlight hover content for the schema definition doc. HOT 2
- [Bug] The loader will return the incorrect number of scopes when there is a schema present
- [Enhancement] Add Unit Test Coverage Feature for KCL Test Tool
- [Feature Request] Enable Unit Test Function Support in IDE Extensions via Click Action
- [Feature Request] Enable Unit Test Function Debugging Running Support in IDE Extensions via Right Click Action HOT 1
- [Bug] Newline completion items loss the attribute that is defined in unification stmt of the schema stmt
- [Bug] Keyword arguments and positional arguments of functions have different highlighting effects on strings.
- Support for podman over docker `"docker-credential-desktop": executable file not found in $PATH` HOT 1
- [Bug] Wrong completion items in the schema statement for complex types.
- Significant performance issue in LSP resolver HOT 2
- Publish KCL extension to https://open-vsx.org/ HOT 2
- Request for API Documentation HOT 2
- [Bug] Unexpected completion items in the schema doc string
- [Enhancement] The KCL Import tool supports automatic grouping based on version during remote resource import and CRD import
- [Enhancement] OverrideFile API supports automatic merging of configuration compilation through the `:` operator
- [Bug] Wrong execution result for merge operator of list index
- [Track] KCL IDE/LSP compile entry design
- Improve LSP performance by skip compiling version behind current version HOT 7
- Expose method in file system package to return current file path HOT 5
- [FAQ] Error when trying to create and use a plugin: Need some clarifications please HOT 1
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 kcl.